function BingMap(options){var _self=this;var _loaded=false;var _defaultOptions={container:"mapsearch-mainmap",fixedMap:false,mapView:VEMapStyle.Shaded,displayListingsOnLoad:true,displayOfficesOnLoad:true,poiEnabled:false,showParcelLines:true,fireOnChange:true,startingMidLat:0,startingMidLon:0,startingZoom:15,showBubble:true,showMinimap:false};var _veMap=null;var _layers={};var _mapContainer=null;var _polyType=options.startingPolyType||"";var _polyValue=options.startingPolyValue||"";var _polyPoints=null;var _mapH=0;var _mapW=0;var _parcelSet=0;var _dontChangeView=false;var _bePinSet=false;var _mapState={};var _movingMap=false;var _pinLayerVisible={all:true};var _pinLayerState=[];var _pinLookups=[];var _poiEnabled=false;var _drawingTempShape=null;var _drawingStartPin=null;var _drawingPan=false;var _drawingPoints=[];function getToggleBubbleHtml(count,curPosition,displayName){var html=new StringBuilder();var displayNames;if(displayName.substring(displayName.length-1,1)=="y"){displayNames=displayName.substring(0,displayName.length-2)+"ies"}else{displayNames=displayName+"s"}html.append('<tr><td valign="top"><table cellspacing="0" cellpadding="0" border="0" class="txt_blk_graybg" width="100%">');html.append('<tr><td colspan="3">Multiple '+displayNames+" found here</td></tr>");html.append('<tr><td align=left width="30%">');if(curPosition>0){html.append('<a href="javascript:;" onclick="javascript:Search.togglePinBubble('+(curPosition-1)+","+curPosition+' )">&lt; Prev</a>')}html.append("</td><td align=center width=40%>");html.append("<b>"+(curPosition+1)+" of "+count+"</b>");html.append("</td><td align=right width=30%>");if(curPosition<count-1){html.append('<a href="javascript:;" onclick="javascript:Search.togglePinBubble('+(curPosition+1)+","+curPosition+')">Next &gt;</a>')}html.append("</td></tr></table></td></tr>");return html.toString()}function meanAverageGridCluster(baseLayer){var gridCells;var gridSize=baseLayer.gridSize||30;var shapeCount=baseLayer.GetShapeCount();var i,j;if(_mapState.Style=="o"||_mapState.Style=="b"){gridCells=[];var bePins=new VEClusterSpecification();bePins.Shapes=[];for(i=0;i<shapeCount;i++){bePins.Shapes.push(baseLayer.GetShapeByIndex(i))}gridCells.push(bePins)}else{var numXCells=parseInt(Math.ceil(_mapW/gridSize),10);var numYCells=parseInt(Math.ceil(_mapH/gridSize),10);gridCells=new Array(numXCells*numYCells);for(i=0;i<shapeCount;i++){var shape=baseLayer.GetShapeByIndex(i);var latLong=(shape.GetPoints())[0];var pixel=_veMap.LatLongToPixel(latLong);var xPixel=pixel.x;var yPixel=pixel.y;if(_mapW>=xPixel&&_mapH>=yPixel&&xPixel>=0&&yPixel>=0){var a=Math.floor(xPixel/gridSize);var b=Math.floor(yPixel/gridSize);var key=a+b*numXCells;var spec=gridCells[key];if(spec==null){spec=new VEClusterSpecification();spec.Shapes=[];gridCells[key]=spec}spec.Shapes.push(shape)}}}var cluster=[];for(var i=0,len=gridCells.length;i<len;i++){var cell=gridCells[i];if(cell!=null&&cell.Shapes.length>0){var size=cell.Shapes.length;var latSum=0;var lonSum=0;for(j=0;j<size;j++){var point=cell.Shapes[j].GetPoints()[0];latSum+=point.Latitude;lonSum+=point.Longitude}cell.LatLong=new VELatLong(latSum/size,lonSum/size);cluster.push(cell)}}return cluster}function clusteringCallback(clusters){for(var i=0,clusterCount=clusters.length;i<clusterCount;++i){var clusterSpec=clusters[i];var clusterShape=clusterSpec.GetClusterShape();var shapes=clusterSpec.Shapes;var firstShape=shapes[0];var pinInfo=BingMap.PinInfo[firstShape.PinType];var imgUrl;if(pinInfo){if(shapes.length==1){imgUrl=pinInfo.ImageOn}else{if(pinInfo.PinType==BingMap.PinType.ListingSold){imgUrl=BingMap.PinInfo[BingMap.PinType.ListingSoldMultiple].ImageOn}else{if(pinInfo.PinType==BingMap.PinType.ListingActive||pinInfo.PinType==BingMap.PinType.ListingNew||pinInfo.PinType==BingMap.PinType.ListingOpenHouse||pinInfo.PinType==BingMap.PinType.ListingPending){imgUrl=BingMap.PinInfo[BingMap.PinType.ListingMultiple].ImageOn}else{imgUrl=pinInfo.ImageOn}}}}else{imgUrl=firstShape.PinType+".gif"}var desc=firstShape.GetDescription();if(!desc||desc==""||desc=="{FROM_BIRDSEYE}"){var pinIDs=new StringBuilder();for(var j=0,shapeCountj=shapes.length;j<shapeCountj;j++){if(j>0){pinIDs.append(",")}pinIDs.append(shapes[j].PinID)}clusterShape.PinID=pinIDs.toString();clusterShape.SetDescription(desc)}else{if(shapes.length>1){var multiDesc=new StringBuilder();for(var k=0,shapeCountk=shapes.length;k<shapeCountk;k++){multiDesc.append('<table width="100%" valign="top" cellspacing="1" cellpadding="1" class="txt_blk" ');if(k>0){multiDesc.append('style="display:none;"')}multiDesc.append(' id="pin_'+k+'">');multiDesc.append(getToggleBubbleHtml(shapeCountk,k,BingMap.PinInfo[shapes[k].PinType].DisplayName));multiDesc.append("<tr><td>"+shapes[k].GetDescription()+"</td></tr>");multiDesc.append("</table>")}clusterShape.SetDescription(multiDesc.toString())}else{clusterShape.SetDescription(firstShape.GetDescription())}}clusterShape.SetCustomIcon(POIImagePath+"POI/"+imgUrl);clusterShape.PinType=firstShape.PinType}}function getLayer(layerType,isPinLayer,cluster,gridSize){if(!_layers[layerType]){var newLayer=new VEShapeLayer();newLayer.isPinLayer=isPinLayer;newLayer.layerType=layerType;if(typeof cluster=="undefined"||cluster==null){cluster=true}if(cluster){newLayer.gridSize=gridSize||30;var options=new VEClusteringOptions();options.Callback=clusteringCallback;newLayer.SetClusteringConfiguration(meanAverageGridCluster,options)}_veMap.AddShapeLayer(newLayer);_layers[layerType]=newLayer}return _layers[layerType]}function gotoFirst(loc){try{if(loc.indexOf(", USA")==-1&&loc.indexOf("mx")==-1){loc+=", USA"}if(loc!=""&&loc!="undefined"){_veMap.Find(null,loc,VEFindType.Businesses,null,null,null,null,null,true,true,null)}}catch(e){}}function updatePOI(removeExisting){var pinLayerName;if(_mapState.Zoom>=12){var pinTypes="";for(var i=5;i<22;i++){pinLayerName="poi-"+i;if(_pinLayerVisible[pinLayerName]){if(pinTypes.length>0){pinTypes+=","}pinTypes+=i}else{if(removeExisting){getLayer(pinLayerName,true).DeleteAllShapes()}}}if(pinTypes.length===0){if(!_poiEnabled){$(_mapContainer).trigger({type:"poichange",poiEnabled:true});_poiEnabled=true}}else{var url="/"+Utils.AppName+"/Include/AJAX/MapSearch/GetPOI.aspx?neLat="+_mapState.NELat+"&neLong="+_mapState.NELon+"&swLat="+_mapState.SWLat+"&swLong="+_mapState.SWLon+"&types="+pinTypes;$.ajax({mode:"abort",port:"poi",type:"GET",url:url,cache:true,dataType:"json",success:function(data){for(var i=0,len=data.length;i<len;i++){var pinType=data[i].PinType;var pinLayerName="poi-"+pinType;_self.startAddingPins(pinLayerName);for(var j=0,poiLen=data[i].POI.length;j<poiLen;j++){var poi=data[i].POI[j];_self.addPin(pinLayerName,"poi-"+pinType+"-"+j,poi.Latitude,poi.Longitude,pinType,poi.DisplayName,poi.Html)}_self.endAddingPins(pinLayerName)}if(!_poiEnabled){$(_mapContainer).trigger({type:"poichange",poiEnabled:true});_poiEnabled=true}},dataFilter:function(data){if(typeof(JSON)!=="undefined"&&typeof(JSON.parse)==="function"){return JSON.parse(data)}else{return eval("("+data+")")}}})}}else{if(_poiEnabled){for(var j=5;j<22;j++){pinLayerName="poi-"+j;getLayer(pinLayerName,true).DeleteAllShapes()}_poiEnabled=false;$(_mapContainer).trigger({type:"poichange",poiEnabled:false})}}}function toggleParcelLines(){if(_veMap){try{var zoomLevel=_veMap.GetZoomLevel();var mapStyle=_veMap.GetMapStyle();if(zoomLevel>=16&&mapStyle!=VEMapStyle.Birdseye){if(_parcelSet===0){if(typeof(_veMap.parcelLayer)=="undefined"){AddDMPParcelLayer(_veMap)}else{SetParcelLayerVisibility(_veMap,true)}_parcelSet=1}}else{_parcelSet=0;SetParcelLayerVisibility(_veMap,false)}if(zoomLevel>=17||mapStyle==VEMapStyle.Birdseye){$("#MSVE_navAction_ObliqueMapView").show()}else{$("#MSVE_navAction_ObliqueMapView").hide()}}catch(e){}}}function getBirdsEyeMapView(){var result;var be=_veMap.GetBirdseyeScene();if(be!=null){var tl=be.PixelToLatLong(new VEPixel(0,0));var br=be.PixelToLatLong(new VEPixel(be.GetWidth(),be.GetHeight()));switch(be.GetOrientation()){case VEOrientation.North:result=new VELatLongRectangle(tl,br,null,null);break;case VEOrientation.East:result=new VELatLongRectangle(new VELatLong(tl.Latitude,br.Longitude),new VELatLong(br.Latitude,tl.Longitude),null,null);break;case VEOrientation.South:result=new VELatLongRectangle(br,tl,null,null);break;case VEOrientation.West:result=new VELatLongRectangle(new VELatLong(br.Latitude,tl.Longitude),new VELatLong(tl.Latitude,br.Longitude),null,null);break}}else{result=new VELatLongRectangle(new VELatLong(0,0),new VELatLong(0,0),null,null)}return result}function getMapView(){var result;if(_veMap.GetMapStyle()==VEMapStyle.Birdseye){result=getBirdsEyeMapView()}else{result=_veMap.GetMapView()}return result}function onChangeStyle(e){if(options.mapView=="o"||options.mapView=="b"){_veMap.SetZoomLevel(19);toggleParcelLines()}}function onObliqueEnter(e){if(!_bePinSet&&(options.mapView=="o"||options.mapView=="b")){$(_mapContainer).trigger("birdseyeavailable");_bePinSet=true}}function onChangeView(e){if(_dontChangeView){_dontChangeView=false;return}var mapStyle=_veMap.GetMapStyle();if(mapStyle!=_mapState.Style){_self.setView(mapStyle);return}_movingMap=false;var mv=getMapView();_mapState={NELat:mv.TopLeftLatLong.Latitude,NELon:mv.BottomRightLatLong.Longitude,SWLat:mv.BottomRightLatLong.Latitude,SWLon:mv.TopLeftLatLong.Longitude,Zoom:_veMap.GetZoomLevel(),PolyPoints:_polyPoints,PolygonType:_polyType,Style:mapStyle};_loaded=true;$(_mapContainer).trigger("mapchange");if(options.showParcelLines){toggleParcelLines()}if(options.poiEnabled){updatePOI(true)}}function setPinDisplay(pinLayerName){var pinLayerCanBeVisible=_pinLayerVisible.all&&_pinLayerVisible[pinLayerName];var pinLayerIsVisible=typeof(_pinLayerState[pinLayerName])!="undefined"?_pinLayerState[pinLayerName]:false;if(pinLayerCanBeVisible&&!pinLayerIsVisible){getLayer(pinLayerName,true).Show()}else{if(!pinLayerCanBeVisible){getLayer(pinLayerName,true).Hide()}}_pinLayerState[pinLayerName]=pinLayerCanBeVisible}function clearPins(pinLayerName){_pinLookups[pinLayerName]=[];_pinLookups[pinLayerName+"ids"]=[]}function getPins(pinLayerName){if(!_pinLookups[pinLayerName]){_pinLookups[pinLayerName]=[]}return _pinLookups[pinLayerName]}function setDescription(shape){var pinid=shape.PinID;if(pinid){var desc=shape.GetDescription();if(desc&&desc!="{FROM_BIRDSEYE}"){return true}if(desc=="{FROM_BIRDSEYE}"&&pinid=="1_"){return false}var divid=new Date().getTime()+"_bubble";shape.SetDescription('<div id="'+divid+'" style="width:100%; text-align:center;"><span style="height:50px;"><br/><br/><img src="'+imageBase+'/search/Images/spinner.gif" border="0" /> Loading...</span></div>');var url="/"+Utils.AppName+"/Include/AJAX/MapSearch/GetListingBubble.aspx?";if(pinid.substring(0,1)=="3"){url+="OfficeID="+pinid.replace(/3_/g,"")}else{url+="ListingID="+pinid.replace(/1_/g,"")}if(desc=="{FROM_BIRDSEYE}"){url+="&birdseye=true"}var qs=new Querystring();if(qs.contains("LayoutID")){url+="&LayoutID="+qs.get("LayoutID")+"&LayoutVersion="+qs.get("LayoutVersion")}$.get(url,null,function(resp){if(resp.indexOf("~~")>0){var desc=new StringBuilder();var arrDesc=resp.split("~~");for(var i=0,len=arrDesc.length;i<len;i++){desc.append('<table width="100%" valign="top" cellspacing="1" cellpadding="1" class="txt_blk" ');if(i>0){desc.append('style="display:none;"')}desc.append(' id="pin_'+i+'">');desc.append(getToggleBubbleHtml(len,i,BingMap.PinInfo[shape.PinType].DisplayName));desc.append("<tr><td>"+arrDesc[i]+"</td></tr>");desc.append("</table>")}resp=desc.toString()}$("#"+divid).parent().html(resp);shape.SetDescription(resp)})}return true}function onmouseover(e){if(options.showBubble&&e.elementID){return !setDescription(_veMap.GetShapeByID(e.elementID))}return true}function getBoundaryShape(latlongs){var boundaryShape=new VEShape(VEShapeType.Polygon,latlongs);boundaryShape.SetFillColor(new VEColor(131,185,187,0.1));boundaryShape.SetLineColor(new VEColor(186,0,255,1));boundaryShape.SetLineWidth(2);boundaryShape.HideIcon();return boundaryShape}function addShapesToLayer(shapes,layer,cb){layer.DeleteAllShapes();var points="";for(var i=0,len=shapes.length;i<len;i++){var shape=shapes[i];points+=shape.GetPoints()+",";layer.AddShape(shapes[i])}if(points.length>0){points=points.substring(0,points.length-1)}if(typeof cb=="function"){cb(shapes,points)}}function addShapesByPolyPoints(points,layer,cb){var latlongs=[];var ctr=0;try{var pointsSplit=points.split(",");for(var i=0,len=pointsSplit.length;i<len/2;i++){latlongs[i]=new VELatLong(parseFloat(pointsSplit[ctr]),parseFloat(pointsSplit[ctr+1]));ctr+=2}addShapesToLayer([getBoundaryShape(latlongs)],layer,cb)}catch(err){Utils.Logger.warn("Error adding polygon from points: "+err.message)}}function addShapesByBoundary(qsParams,layer,cb){if(typeof qsParams=="undefined"){return}$.ajax({type:"GET",url:"/"+Utils.AppName+"/Include/AJAX/mapsearch/GetBoundary.aspx",data:qsParams,dataType:"json",dataFilter:function(data){if(typeof(JSON)!=="undefined"&&typeof(JSON.parse)==="function"){return JSON.parse(data)}else{return eval("("+data+")")}},success:function(polygons){var shapes=[];try{for(var i=0,len=polygons.length;i<len;i++){var latlongs=[];var polygon=polygons[i];var j=polygon.Points.length;if(j>0){do{var point=polygon.Points[j-1];latlongs.push(new VELatLong(parseFloat(point[1]),parseFloat(point[0])))}while(--j)}shapes.push(getBoundaryShape(latlongs))}}catch(ex){Utils.Logger.warn(ex.message)}addShapesToLayer(shapes,layer,cb)}})}function addShapes(polyLayer,cb){if(!_polyType||_polyType==""||_polyType=="points"){addShapesByPolyPoints(_polyValue,polyLayer,cb)}else{var state="";var polyVal=_polyValue;if(_polyType=="city"){state=defaultState;if(polyVal.indexOf(",")>-1){var citystate=polyVal.split(",");polyVal=citystate[0].trim();state=citystate[1].trim()}}addShapesByBoundary({val:polyVal,type:_polyType,state:state},polyLayer,cb)}}function toggleMiniMap(){var $toggle=$("#minimap-toggle");var $img=$("#minimap-toggle img");if($toggle.is(".minimap-on")){_veMap.HideMiniMap();$toggle.css({bottom:0,left:0});$toggle.removeClass("minimap-on");$img.attr("src","/Images/Common/Map/images/mapcontrol/minimap_show.gif");$img.attr("alt","Show Mini Map");$img.attr("title","Show Mini Map")}else{_veMap.ShowMiniMap(0,_mapH-150);$("#MSVE_minimap_resize").hide();$toggle.addClass("minimap-on");$toggle.css({bottom:127,left:129});$img.attr("src","/Images/Common/Map/images/mapcontrol/minimap_hide.gif");$img.attr("alt","Hide Mini Map");$img.attr("title","Hide Mini Map")}}this.load=function(){_loaded=false;options=$.extend({},_defaultOptions,options);_pinLayerVisible.listing=options.displayListingsOnLoad;_pinLayerVisible.office=options.displayOfficesOnLoad;_pinLayerVisible.address=true;_mapContainer=document.getElementById(options.container);_mapH=$(_mapContainer).height();_mapW=$(_mapContainer).width();_veMap=new VEMap(options.container);_veMap.LoadMap(new VELatLong(options.startingMidLat,options.startingMidLong),options.startingZoom,options.mapView,options.fixedMap,VEMapMode.Mode2D,false);_self.setView(options.mapView);_veMap.SetMouseWheelZoomToCenter(false);_veMap.AttachEvent("onchangemapstyle",onChangeStyle);_veMap.AttachEvent("onobliqueenter",onObliqueEnter);_veMap.AttachEvent("onmouseover",onmouseover);if(options.centerPin){_self.startAddingPins("address");_self.addPin("address","1",options.startingMidLat,options.startingMidLong,25,"","Center Pin");_self.endAddingPins("address");$(_mapContainer).pngFix()}if(options.fixedMap){$(_mapContainer).css("cursor","default");if(options.showParcelLines){toggleParcelLines()}_loaded=true}else{if(options.fireOnChange){_veMap.AttachEvent("onchangeview",onChangeView)}if(options.showMinimap){$("<div style='position: absolute; bottom: 0; left: 0; z-index: 1000; cursor: pointer;' id='minimap-toggle'><img alt='Show Mini Map' title='Show Mini Map' src='/Images/Common/Map/images/mapcontrol/minimap_show.gif' border='0'/></div>").click(toggleMiniMap).appendTo($(_mapContainer))}if(_polyValue!=""){_self.gotoPoly(_polyType,_polyValue)}else{onChangeView()}}};this.setOptions=function(opts){if(opts){options=$.extend({},options,opts);if(options.displayListingsOnLoad){_self.showPins("listing")}else{_self.hidePins("listing")}if(options.displayOfficesOnLoad){_self.showPins("office")}else{_self.hidePins("office")}_self.setView(options.mapView)}};this.isLoaded=function(){return _loaded};this.resize=function(w,h){if(typeof h=="undefined"){h=_mapH}if(w===0||h===0){return}if(w!=_mapW||h!=_mapH){_mapW=w;_mapH=h;var currCenter=_veMap.GetCenter();_dontChangeView=true;_veMap.Resize(w,h);_veMap.PanToLatLong(currCenter);$(_mapContainer).width(w);$(_mapContainer).height(h);if($("#minimap-toggle.minimap-on").length>0){_veMap.ShowMiniMap(0,_mapH-150);$("#MSVE_minimap_resize").hide()}}};this.dispose=function(){$.each(_layers,function(layerName,layer){clearPins(layerName);layer=null});_pinLookups.length=0;if(_veMap){_veMap.Dispose();_veMap=null}};this.setCenterAndZoom=function(lat,lon,zoom){_veMap.SetCenterAndZoom(new VELatLong(lat,lon),zoom);setTimeout(function(){if(_movingMap){_movingMap=false;$(_mapContainer).trigger("mapchange")}},500)};this.setView=function(view){var newView,oldView;oldView=_veMap.GetMapStyle();if(view=="r"||view=="s"){newView=VEMapStyle.Shaded}else{if(view=="h"){newView=VEMapStyle.Hybrid}else{if(view=="a"){newView=VEMapStyle.Aerial}else{if(view=="b"||view=="o"){newView=VEMapStyle.Birdseye}}}}if(newView!=oldView){_veMap.SetMapStyle(newView);var justsetview=_veMap.GetMapStyle();if(justsetview!=newView&&newView==VEMapStyle.Birdseye){newView=VEMapStyle.Aerial;_veMap.SetMapStyle(VEMapStyle.Aerial);_veMap.SetZoomLevel(19);$(_mapContainer).trigger("mapviewnotsupported")}}if(newView==VEMapStyle.Birdseye){_veMap.SetShapesAccuracy(VEShapeAccuracy.Pushpin)}else{_veMap.SetShapesAccuracy(VEShapeAccuracy.None)}_mapState.Style=newView};this.getMapState=function(){return _mapState};this.showControls=function(){_veMap.ShowInfoBox();_veMap.ShowDashboard();_veMap.ShowScalebar()};this.hideControls=function(){_veMap.HideInfoBox();_veMap.HideDashboard();_veMap.HideScalebar()};this.showAllPins=function(){_pinLayerVisible.all=true;$.each(_layers,function(layerName,layer){if(layer.isPinLayer){setPinDisplay(layerName)}})};this.hideAllPins=function(){_pinLayerVisible.all=false;$.each(_layers,function(layerName,layer){if(layer.isPinLayer){setPinDisplay(layerName)}})};this.hidePins=function(pinLayerName){_pinLayerVisible[pinLayerName]=false;setPinDisplay(pinLayerName)};this.showPins=function(pinLayerName){_pinLayerVisible[pinLayerName]=true;setPinDisplay(pinLayerName)};this.hidePOI=function(pinType){var pinLayerName="poi-"+pinType;_pinLayerVisible[pinLayerName]=false;setPinDisplay(pinLayerName)};this.showPOI=function(pinType){var pinLayerName="poi-"+pinType;_pinLayerVisible[pinLayerName]=true;setPinDisplay(pinLayerName);if(getLayer(pinLayerName,true).GetShapeCount()===0){updatePOI(false)}};this.hideAllPOI=function(){$.each(_layers,function(layerName,layer){if(layer.isPinLayer&&layerName.indexOf("poi-")==0){_pinLayerVisible[layerName]=false;setPinDisplay(layerName)}})};this.showAllPOI=function(){var update=false;$.each(_layers,function(layerName,layer){if(layer.isPinLayer&&layerName.indexOf("poi-")==0){_pinLayerVisible[layerName]=true;setPinDisplay(layerName);if(layer.GetShapeCount()===0){update=true}}});if(update){updatePOI(false)}};this.pinsAreVisible=function(pinLayerName){var visible=_pinLayerVisible[pinLayerName];return(typeof visible=="boolean")&&visible};this.deleteAllPins=function(pinLayerName){getLayer(pinLayerName,true).DeleteAllShapes()};this.startAddingPins=function(pinLayerName,cluster){getLayer(pinLayerName,true,cluster).DeleteAllShapes();clearPins(pinLayerName)};this.addPin=function(pinLayerName,id,pinLat,pinLong,pinType,pinTitle,pinDesc){var shape=new VEShape(VEShapeType.Pushpin,new VELatLong(parseFloat(pinLat),parseFloat(pinLong)));if(pinTitle&&pinTitle.length>0){shape.SetTitle(pinTitle)}if(pinDesc&&pinDesc.length>0){shape.SetDescription(pinDesc)}var imgFilename;var pinInfo=BingMap.PinInfo[pinType];var imgFilename=typeof(pinInfo)=="undefined"?pinType+".gif":pinInfo.ImageOn;shape.PinID=id;shape.PinType=pinType;shape.SetCustomIcon(POIImagePath+"POI/"+imgFilename);getPins(pinLayerName+"ids")[id]=shape;getPins(pinLayerName).push(shape)};this.endAddingPins=function(pinLayerName,bestview){var pins=getPins(pinLayerName);if(bestview){_veMap.SetMapView(pins)}try{getLayer(pinLayerName,true).AddShape(pins)}catch(e){Utils.Logger.warn("Error adding "+pinLayerName+" pins to map: "+e.message)}setPinDisplay(pinLayerName)};this.addAddressPin=function(address){if(address.indexOf(", USA")==-1&&address.indexOf("mx")==-1){address+=", USA"}_veMap.Find(null,address,null,null,1,null,true,null,null,null,function(shapeLayer,findResults,places){var bestPlace=places[0];var location=bestPlace.LatLong;_self.startAddingPins("address");_self.addPin("address","1",location.Latitude,location.Longitude,BingMap.PinType.Flag,"",bestPlace.Name);_self.endAddingPins("address");$(_mapContainer).pngFix()})};this.showListingBubble=function(bubbleID){var pin=getPins("listingids")[bubbleID];if(pin&&setDescription(pin)){_veMap.ShowInfoBox(pin)}};this.hideListingBubble=function(){_veMap.HideInfoBox()};this.clearPolygons=function(change){getLayer("poly",false,false).DeleteAllShapes();_polyPoints=null;_polyValue=null;_polyType=null;if(change){onChangeView()}};this.gotoPoly=function(polyType,polyValue){_polyValue=polyValue.toString();_polyType=polyType;if(_polyValue.indexOf("(")>0){_polyValue=_polyValue.substring("(").trim()}addShapes(getLayer("poly",false,false),function(shapes,points){_polyPoints=points;_movingMap=true;if(shapes&&shapes.length>0){_veMap.SetMapView(shapes)}else{gotoFirst(_polyValue)}setTimeout(function(){if(_movingMap){_movingMap=false;$(_mapContainer).trigger("mapchange")}},500)})};function getClickLatLong(e){var pixel=new VEPixel(e.mapX,e.mapY);var latLong=_veMap.PixelToLatLong(pixel);latLong.Latitude*=10000;latLong.Latitude=Math.floor(latLong.Latitude)/10000;latLong.Longitude*=10000;latLong.Longitude=Math.floor(latLong.Longitude)/10000;return latLong}function drawingClick(e){_drawingPoints.push(getClickLatLong(e))}function drawingMouseOut(e){var x=0;var y=0;var br=_veMap.LatLongToPixel(_veMap.GetMapView().BottomRightLatLong);if(e.mapX<15||e.mapX>br.x-15){if(e.mapX<15){x=-2}else{x=2}}if(e.mapY<15||e.mapY>br.y-15){if(e.mapY<15){y=-2}else{y=2}}if(x!=0||y!=0){_veMap.StartContinuousPan(x,y);_drawingPan=true}else{if(_drawingPan){_veMap.EndContinuousPan();_drawingPan=false}}}function drawingMouseOver(e){if(_drawingPan){_veMap.EndContinuousPan();_drawingPan=false}}function drawingMouseMove(e){if(_drawingPoints.length==0){return}var polyLayer=getLayer("poly",false,false);var points=_drawingPoints.slice(0);points.push(getClickLatLong(e));if(_drawingTempShape){polyLayer.DeleteShape(_drawingTempShape)}if(points.length<3){_drawingTempShape=new VEShape(VEShapeType.Polyline,points)}else{_drawingTempShape=new VEShape(VEShapeType.Polygon,points)}_drawingTempShape.SetFillColor(new VEColor(153,153,153,0.4));_drawingTempShape.SetLineColor(new VEColor(153,153,153,1));_drawingTempShape.SetLineWidth(2);_drawingTempShape.HideIcon();polyLayer.AddShape(_drawingTempShape);if(_drawingPoints.length==1){_veMap.AttachEvent("onmouseout",drawingMouseOut);_veMap.AttachEvent("onmouseover",drawingMouseOver);$(_mapContainer).trigger({type:"polypointchange",tipID:2})}if(_drawingPoints.length==3){if(_drawingStartPin==null){_drawingStartPin=new VEShape(VEShapeType.Pushpin,_drawingPoints[0]);_drawingStartPin.SetCustomIcon("<img src='/Images/Common/Map/Images/mapcontrol/bttn-drawpolygon-end2.gif' onclick='Search.endDrawing()' />");_drawingStartPin.ShowDetailOnMouseOver=false;polyLayer.AddShape(_drawingStartPin)}$(_mapContainer).trigger({type:"polypointchange",tipID:3})}}this.startDrawing=function(){_self.clearPolygons();getLayer("listing",true,true).DeleteAllShapes();_self.hideAllPins();_drawingPoints=[];$(_mapContainer).css("cursor","crosshair");_veMap.AttachEvent("onclick",drawingClick);_veMap.AttachEvent("onmousemove",drawingMouseMove);_veMap.DetachEvent("onchangeview",onChangeView);_veMap.vemapcontrol.EnableGeoCommunity(true);$(_mapContainer).trigger({type:"polypointchange",tipID:1})};this.endDrawing=function(cancel){_veMap.DetachEvent("onclick",drawingClick);_veMap.DetachEvent("onmousemove",drawingMouseMove);_veMap.DetachEvent("onmouseout",drawingMouseOut);_veMap.DetachEvent("onmouseover",drawingMouseOver);if(options.fireOnChange&&!options.fixedMap){_veMap.AttachEvent("onchangeview",onChangeView)}_veMap.vemapcontrol.EnableGeoCommunity(false);var polyLayer=getLayer("poly",false,false);polyLayer.DeleteAllShapes();if(_drawingPan){_veMap.EndContinuousPan();_drawingPan=false}_drawingStartPin=null;_drawingTempShape=null;$(_mapContainer).css("cursor","default");$(_mapContainer).trigger({type:"polypointchange",tipID:0});if(!cancel&&_drawingPoints.length>=3){_drawingPoints.push(_drawingPoints[0]);addShapesByPolyPoints(_drawingPoints.toString(),polyLayer,function(shapes,points){_polyPoints=points;_polyValue="points";onChangeView()})}else{getLayer("poly",false,false);onChangeView()}_self.showAllPins()};this.plotComps=function(latLons){var arrLatLon=latLons.split(",");var len=arrLatLon.length;var latLon,lat,lon;_self.startAddingPins("comp",false);for(var i=0;i<len;i++){if(arrLatLon[i]==""){continue}latLon=arrLatLon[i].split(" ");lat=latLon[0];lon=latLon[1];if(lat!=""&&lon!=""&&lat!="undefined"&&lon!="undefined"){_self.addPin("comp","comp_"+i,lat,lon,"listing_"+(i+1),"","")}}_self.endAddingPins("comp",true);_self.showPins("comp")};var _locations;this.getDirections=function(locations){_locations=locations;var options=new VERouteOptions();options.RouteCallback=onGotRoute;options.ShowDisambiguation=true;options.DistanceUnit=VERouteDistanceUnit.Mile;_veMap.GetDirections(locations,options)};function formatTime(time){if(!time){return("")}if(time>60){var seconds=time%60;var minutes=time-seconds;minutes=minutes/60;if(minutes>60){var minLeft=minutes%60;var hours=minutes-minLeft;hours=hours/60;return(hours+" hrs, "+minLeft+" mins, "+seconds+" secs")}else{return(minutes+" mins, "+seconds+" secs")}}else{return(time+" secs")}}function onGotRoute(route){var routeInfo=new StringBuilder();var legs=route.RouteLegs;var turnNum=0;var $route=$("#dd-route");routeInfo.append('<table width="100%" border="0" cellspacing="2" cellpadding="2" class="dd_txt">');routeInfo.append('<tr><td colspan="4" class="dd_tableHeader1">');routeInfo.append("Total Distance: ");routeInfo.append(route.Distance.toFixed(1));routeInfo.append(" miles");routeInfo.append("<br/>Total Time: ");routeInfo.append(formatTime(route.Time));routeInfo.append("</td></tr>");for(var i=0,len=legs.length;i<len;i++){var leg=legs[i];var turn=null;var legNum=i+1;routeInfo.append('<tr><td colspan="4" class="dd_tableHeader2" nowrap="nowrap"><b>From: </b>');routeInfo.append(_locations[i]);routeInfo.append("<br/><b>To: </b>");routeInfo.append(_locations[i+1]);routeInfo.append("<br/><b>Time: </b>");routeInfo.append(formatTime(leg.Time));routeInfo.append("</td></tr>");$("#routeFrom").val(_locations[i]);$("#routeTo").val(_locations[i+1]);for(var j=0,len2=leg.Itinerary.Items.length;j<len2;j++){turn=leg.Itinerary.Items[j];routeInfo.append("<tr>");if(i==0&&j==0){routeInfo.append('<td align="center"><img src="/images/common/map/images/DrivingDirection/pin_Start.gif"/></td>')}else{if(i==len-1&&j==len2-1){routeInfo.append('<td align="center"><img src="/images/common/map/images/DrivingDirection/pin_End.gif"/></td>')}else{routeInfo.append('<td align="center"><div class="dd_number">');routeInfo.append(turnNum);routeInfo.append("</div></td>")}}routeInfo.append('<td class="hseparator">');routeInfo.append(turn.Text);routeInfo.append("</td>");routeInfo.append("<td>");if(turn.Distance!=null){routeInfo.append(turn.Distance.toFixed(1))}routeInfo.append("</td></tr>");turnNum++}}routeInfo.append("</table>");$route.html(routeInfo.toString())}}BingMap.PinType={ListingActive:1,ListingOther:2,Office:3,ListingMultiple:4,Childcare:5,Schools:6,Restaurants:7,Shopping:8,Grocery:9,Gas:10,Bank:11,Park:12,Hospital:13,Transport:14,Lodging:15,Worship:16,Police:17,Fire:18,Library:19,PostOffice:20,Cultural:21,Multiple:22,ListingOpenHouse:23,ListingSold:24,Flag:25,ListingNew:26,ListingPending:27,ListingSoldMultiple:28};BingMap.PinInfo=[{},{PinType:BingMap.PinType.ListingActive,ShortName:"activelisting",DisplayName:"Listing",ImageOn:"listing_active.gif",ImageOff:"listing_active_off.gif",ImageDisabled:null},{PinType:BingMap.PinType.ListingOther,ShortName:"otherlisting",DisplayName:"Other Listing",ImageOn:"listing_other.gif",ImageOff:"listing_other_off.gif",ImageDisabled:null},{PinType:BingMap.PinType.Office,ShortName:"office",DisplayName:"Office",ImageOn:"office.gif",ImageOff:"office_off.gif",ImageDisabled:null},{PinType:BingMap.PinType.ListingMultiple,ShortName:"multiplelistings",DisplayName:"Multiple Listings",ImageOn:"listing_multiple.gif",ImageOff:"listing_multiple_off.gif",ImageDisabled:null},{PinType:BingMap.PinType.Childcare,ShortName:"childcare",DisplayName:"Child Care",ImageOn:"childcare_on.gif",ImageOff:"childcare_off.gif",ImageDisabled:"childcare_dis.gif"},{PinType:BingMap.PinType.Schools,ShortName:"schools",DisplayName:"School",ImageOn:"schools_on.gif",ImageOff:"schools_off.gif",ImageDisabled:"schools_dis.gif"},{PinType:BingMap.PinType.Restaurants,ShortName:"restaurants",DisplayName:"Restaurant",ImageOn:"restaurants_on.gif",ImageOff:"restaurants_off.gif",ImageDisabled:"restaurants_dis.gif"},{PinType:BingMap.PinType.Shopping,ShortName:"shopping",DisplayName:"Shopping",ImageOn:"shopping_on.gif",ImageOff:"shopping_off.gif",ImageDisabled:"shopping_dis.gif"},{PinType:BingMap.PinType.Grocery,ShortName:"grocery",DisplayName:"Grocery",ImageOn:"grocery_on.gif",ImageOff:"grocery_off.gif",ImageDisabled:"grocery_dis.gif"},{PinType:BingMap.PinType.Gas,ShortName:"gas",DisplayName:"Gas Station",ImageOn:"gas_on.gif",ImageOff:"gas_off.gif",ImageDisabled:"gas_dis.gif"},{PinType:BingMap.PinType.Bank,ShortName:"bank",DisplayName:"Bank",ImageOn:"bank_on.gif",ImageOff:"bank_off.gif",ImageDisabled:"bank_dis.gif"},{PinType:BingMap.PinType.Park,ShortName:"park",DisplayName:"Entertainment/Recreation",ImageOn:"park_on.gif",ImageOff:"park_off.gif",ImageDisabled:"park_dis.gif"},{PinType:BingMap.PinType.Hospital,ShortName:"hospital",DisplayName:"Hospital",ImageOn:"hospital_on.gif",ImageOff:"hospital_off.gif",ImageDisabled:"hospital_dis.gif"},{PinType:BingMap.PinType.Transport,ShortName:"transport",DisplayName:"Transportation",ImageOn:"transport_on.gif",ImageOff:"transport_off.gif",ImageDisabled:"transport_dis.gif"},{PinType:BingMap.PinType.Lodging,ShortName:"lodging",DisplayName:"Hotel",ImageOn:"lodging_on.gif",ImageOff:"lodging_off.gif",ImageDisabled:"lodging_dis.gif"},{PinType:BingMap.PinType.Worship,ShortName:"worship",DisplayName:"Worship",ImageOn:"worship_on.gif",ImageOff:"worship_off.gif",ImageDisabled:"worship_dis.gif"},{PinType:BingMap.PinType.Police,ShortName:"police",DisplayName:"Police Department",ImageOn:"police_on.gif",ImageOff:"police_off.gif",ImageDisabled:"police_dis.gif"},{PinType:BingMap.PinType.Fire,ShortName:"fire",DisplayName:"Fire Department",ImageOn:"fire_on.gif",ImageOff:"fire_off.gif",ImageDisabled:"fire_dis.gif"},{PinType:BingMap.PinType.Library,ShortName:"library",DisplayName:"Library",ImageOn:"library_on.gif",ImageOff:"library_off.gif",ImageDisabled:"library_dis.gif"},{PinType:BingMap.PinType.PostOffice,ShortName:"postoffice",DisplayName:"Post Office",ImageOn:"postoffice_on.gif",ImageOff:"postoffice_off.gif",ImageDisabled:"postoffice_dis.gif"},{PinType:BingMap.PinType.Cultural,ShortName:"cultural",DisplayName:"Cultural Center",ImageOn:"cultural_on.gif",ImageOff:"cultural_off.gif",ImageDisabled:"cultural_dis.gif"},{PinType:BingMap.PinType.Multiple,ShortName:"multiple",DisplayName:"Multiple",ImageOn:"multiple_on.gif",ImageOff:"multiple_off.gif",ImageDisabled:"multiple_dis.gif"},{PinType:BingMap.PinType.ListingOpenHouse,ShortName:"openhouselisting",DisplayName:"Open House",ImageOn:"listing_openhouse.gif",ImageOff:"listing_openhouse_off.gif",ImageDisabled:null},{PinType:BingMap.PinType.ListingSold,ShortName:"soldlisting",DisplayName:"Sold Listing",ImageOn:"listing_sold.gif",ImageOff:"listing_sold_off.gif",ImageDisabled:null},{PinType:BingMap.PinType.Address,ShortName:"address",DisplayName:"Address",ImageOn:"red-flag-only.png",ImageOff:null,ImageDisabled:null},{PinType:BingMap.PinType.ListingNew,ShortName:"newlisting",DisplayName:"New Listing",ImageOn:"listing_newlisting.gif",ImageOff:"listing_newlisting_off.gif",ImageDisabled:null},{PinType:BingMap.PinType.ListingPending,ShortName:"pendinglisting",DisplayName:"Pending Listing",ImageOn:"listing_pending.gif",ImageOff:"listing_pending_off.gif",ImageDisabled:null},{PinType:BingMap.PinType.ListingSoldMultiple,ShortName:"multiplesoldlistings",DisplayName:"Multiple Sold Listings",ImageOn:"listing_sold_multiple.gif",ImageOff:"listing_sold_multiple_off.gif",ImageDisabled:null}];var DMP_AUTH_STATUS="VALID";var ReturnGeometryType={NONE:2,CENTRIOD:3,CENTROID:3,GEOMETRY:1,LATLON:4};function DMCException(b,a){this.msgCode=a;this.description=b;this.message=b;this.getMessage=c;this.toString=c;function c(){return b}}function DMCQueryControl(v,m){var b="http://parcelstream.com/Query.aspx";if(v!=null){b=v}var a="y_coord";var u="x_coord";var A=m;var t=null;var y=-1;var q=1;var k=0;var d="@@@@";var G=t;var C=200;var f=null;var p=null;var e=null;var o="json";var F=0;var r=false;var l=-1;var z=false;var h=20;var c=null;var j=null;var g=null;var s=null;var x=null;var B=0;var D=ReturnGeometryType.GEOMETRY;var w=null;var n=null;this.setKeyField=function(H){n=H};this.getKeyField=function(){return n};this.setLatitudeField=function(H){a=H};this.setLongitudeField=function(H){u=H};this.getSelectAttributeName=function(){return"attr"};this.getAttributeCondName=function(){return"attrConds"};this.setSelectAttributes=function(H){G=H};this.getSelectAttributes=function(){return G};this.setMaxOutputRecords=function(H){C=H};this.setOrderByAttribute=function(H){f=H};this.setWhereClause=function(I,H){p=I;e=H};this.setAPNFilter=function(I,H){j=I;g=H};this.setID=function(H){c=H};this.setGeometryFilter=function(H){s=H};this.setSpatialReference=function(H){x=H};this.setGeometryBufferDistance=function(H){B=H};this.setReturnGeometryType=function(H){D=H};this.setOutputType=function(H){o=H};this.setMinRecords=function(H){F=H};this.setNoSchema=function(H){r=H};this.setNoRecordsIfOverN=function(H){l=H};this.setIsTileOutSearch=function(H){z=H};this.setMaxRadius=function(H){h=H};this.getQueryServiceUrl=function(){return b};this.getResourceName=function(){return A};this.getDataSource=function(){return A};this.setDataSource=function(H){A=H};this.getQuery=function(){var I=b+"?";if(p!=null&&p.length>0){I+="attrConds=";if(typeof(p)=="string"){I+=this.encodeParameter(p)}else{for(var J=0;J<p.length;J++){var K=p[J];if(K==null||K==""){continue}I+=this.encodeParameter(K);if(J!=p.length-1){I+=d}}}}if(e!=null){I+="&andCond="+this.encodeParameter(e)}var H=G;if(D!=null&&D>=0){if(D==ReturnGeometryType.LATLON){H=H.toUpperCase();H=ReplaceString(H,"GEOMETRY",a+" AS _LATFIELD,"+u+" AS _LONFIELD")}else{I+="&returnGeoType="+D}}if(H!=null){I+="&attr="+this.encodeParameter(H)}if(C!=null){I+="&maxRecords="+C}if(A!=null&&A.length>0){I+="&DataSource="+this.encodeParameter(A)}if(f!=null){I+="&orderBy="+this.encodeParameter(f)}if(x!=null&&x.length>0){I+="&srs="+this.encodeParameter(x)}if(B!=null&&B>0){I+="&geoBufferDist="+B}if(s!=null){I+="&geoFilter="+this.encodeParameter(s)}if(c){I+="&ID="+this.encodeParameter(c)}else{if(j&&g){I+="&APN="+this.encodeParameter(j);I+="&FIPS="+this.encodeParameter(g)}}if(o!=null&&o.toLowerCase()!="json"){I+="&output="+this.encodeParameter(o)}if(F!=null&&F>0){I+="&minRecords="+this.encodeParameter(F)}if(r!=null&&r==true){I+="&noSchema=true"}if(l!=null&&l>1){I+="&noRecordsIfOverN="+this.encodeParameter(l)}if(z!=null&&z==true&&s!=null){I+="&isTileOutSearch=true";if(h!=null&&h>1){I+="&maxRadius="+this.encodeParameter(h)}if(a!=null){I+="&latField="+this.encodeParameter(a)}if(u!=null){I+="&lonField="+this.encodeParameter(u)}}return I};this.geocode=function(P,J,K,I,O,N,L,M,Q,H){if(w==null){w=new DMPGeocoder()}w.geocodeByAddress(P,J,K,O,N,L,M,Q,H)};var E=0;this.execute=function(I,H,M,K){var J=this.getQuery();try{var N=new _DMCQueryControlObserver(I,H,M,this.getResourceName(),n);if(K==null||typeof(K)=="undefined"){K="query"+K++}gLoadJSON(J,N,"onSuccess","onError",K)}catch(L){alert("Error DMCQueryCOntrol:"+L.description)}};this.encodeParameter=function(H){if(H!=null){return encodeURIComponent(H)}return""}}function _DMCQueryControlObserver(c,a,f,e,b){if(c==null){throw new DMCException("DMCQueryControlObserver: observer is undefined")}if(c[a]==null){throw new DMCException("DMCQueryControlObserver: observer must have a success method '"+a+"()' ")}if(c[f]==null){throw new DMCException("DMCQueryControlObserver: observer must have an error method '"+f+"()' ")}var d=this;this._observer=c;this._onSuccessMethod=a;this._onErrorMethod=f;this._dataSourceName=e;this.onSuccess=function(g,h,k){if(b==null&&typeof(c.getKeyField)!="undefined"){b=c.getKeyField()}var l=d._dataSourceName;if(c.getLayerName){l=c.getLayerName()}var j=JSON2RecordSet(g,b,l);c[a](j,e)};this.onError=function(h,j,g){c[f](h,j,g)};this.tryParse=function(h,g){if(h==null||g==null){return g}if(h=="int"){return parseInt(g)}else{if(h=="double"||h=="float"){return parseFloat(g)}else{if(h=="bool"){if(g=="1"||g=="true"){return true}else{return false}}else{return g}}}}}function DMPGeocoder(c){var d=1;var e="http://parcelstream.com/Geocode.aspx";if(c!=null){e=c}var a=["ID","DATASOURCE","ADDRESS","ZIP"];this.geocodeByAddress=function(p,g,h,o,m,j,k,q,f){if(f!=null&&f==true){f="true"}else{f=""}var r=e+"?";r+=b("address",o);r+=b("city",m);r+=b("state",j);r+=b("zip",k);r+=b("includeGeo",f);r+=b("minScore",q);try{var l=new _DMCQueryControlObserver(p,g,h,"",a);d=d++;gLoadJSON(r,l,"onSuccess","onError",d)}catch(n){alert("Error DMPGeocoder:"+n.description)}};function b(f,g){if(typeof(g)!="undefined"&&typeof(f)!="undefined"&&f!=null&&f!=""&&g!=""&&g!=null){return"&"+f+"="+encodeURIComponent(g)}return""}}function CPriority(){this.LOW=1000;this.MEDIUM=20;this.HIGH=2;this.HIGHEST=1}var Priority=new CPriority();if(typeof(Dmp)=="undefined"){Dmp=new Object()}Dmp.Event=function(b,a,c){this.eventType=b;this.consumed=false;this.source=a;this.data=(c?c:a);this.cancel=false;this.getSource=function(){return this.source};this.getStatus=function(){return this.eventType};this.getEventType=function(){return this.eventType};this.getData=function(){return this.data}};Dmp.EventManager=function(){this._event2PriorityArray=new Array();this._eventPassed=new Array();this.notify=function(d){if(d==null){throw new DMCException("Event object is NULL")}if(d.eventType==null){throw new DMCException("evtObj.eventType is NULL")}if(d.deadEvent){this.setDispatchedEvent(d.eventType,d)}var e=this._event2PriorityArray[d.eventType];if(e==null){return null}for(var f=0;f<e.length;f++){var b=e[f];var c=b.observer;var g=b.funcName;c[g](d);if(d.cancel==true){return}}};this.setDispatchedEvent=function(c,b){this._eventPassed[c]=b};this.addObserver=function(j,e,d,k,f){if(j==null||d==null){return}if(e==null){e="handleEvent"}if(k==null){k=20}if(j[e]==null){throw new DMCException("An observer must support "+e+" method.")}var h=this._eventPassed[d];if(h!=null&&typeof(f)!=undefined&&f!=true){j[e](h)}var b=this._event2PriorityArray[d];if(b==null){b=new Array();this._event2PriorityArray[d]=b}var g=this.indexOf(b,j);if(g<0){g=b.length;var c=new Object();c.observer=j;c.funcName=e;c.eventType=d;c.priority=k;b[g]=c}b.sort(a)};function a(c,d){if(c.priority==null){c.priority=20}if(d.priority==null){d.priority=20}if(c.priority<d.priority){return -1}else{if(c.priority>d.priority){return 1}else{return 0}}}this.indexOf=function(c,b){if(c==null||b==null){return -1}for(var d=0;d<c.length;d++){if(c[d].observer==b){return d}}return -1};this.remove=function(b,c){return this.removeObserver(b,c)};this.removeObserver=function(b,c){if(c==null){return}if(b==null){return removeAll(c)}var d=this._event2PriorityArray[c];if(d==null){return}var f=[];for(var e=0;e<d.length;e++){if(d[e].observer==b){continue}f.push(d[e])}this._event2PriorityArray[c]=f};this.removeAll=function(b){if(b==null){return}var c=this._event2PriorityArray[b];if(c==null){return}this._event2PriorityArray[b]=null}};function _gNotifyAsyncObs(_gid){try{var po=null;var eo=null;var str="po = window.PO"+_gid+"; window.PO"+_gid+" = null;";eval(str);eval("eo = window.EO"+_gid+"; window.PO"+_gid+" = null;");if(po==null){return}po._dmc_notifyEvent(eo.eventType,eo)}catch(ex){alert("_gNotifyAsyncObs: "+ex.description)}}function _dmc_notifyEvent(eventType,evtObj){if(eventType==null){eventType=evtObj.eventType}var funcName=this._dmcEventMethodNames[eventType];eval("this."+funcName+"(evtObj);")}if(typeof(Event)=="undefined"){Event=Dmp.Event}if(typeof(EventManager)=="undefined"){EventManager=Dmp.EventManager}function JSON2RecordSet(c,v,a){var w=false;if(v==null||v.length==0||(v.length==1&&v[0]=="")){v="_ridx";w=true}if(typeof(v)=="string"){v=[v]}var f=new Array();var m=[];if(c!=null){var g=null;try{g=c.Xml.Data.Row}catch(d){}if(g==null){g=new Array()}var r=null;if(c.Xml.Schema){r=c.Xml.Schema.ElementType.AttributeType}if(g&&g.length==null){g=[g]}if(r&&r.length==null){r=[r]}var n=[];if(r){for(var j=0;j<r.length;j++){var t=r[j].Datatype.type;m[r[j].name]=t;n[r[j].name]=r[j].basecolumn}}for(var j=0;j<g.length;j++){var e=g[j];var h=new Dmp.Record(v,a);if(w){h.setByName(v[0],(j+1)+"","string")}if(e._LATFIELD&&e._LONFIELD&&e.GEOMETRY==null){var l=tryParse("double",e._LATFIELD);var u=tryParse("double",e._LONFIELD);h.setByName("GEOMETRY",new DMCPoint(u,l),"geometry")}var p=0;for(property in e){if(property=="_LATFIELD"||property=="_LONFIELD"){continue}var o=n[property];if(o==null){o=property}var x=m[property];if(x==null){x="string"}var t=x=="wkt"?"geometry":x;h.setByName(o,tryParse(x,e[property]),t)}f.push(h)}}var s="QueryRecordset";if(a!=null&&a.length>0){s=a}var k=[];if(w){k.push(v[0])}for(var b in m){k.push(b)}var q=new Dmp.RecordSet(v,k);q.addRecordCollection(f);return(q)}function tryParse(b,a){if(b==null||a==null){return a}if(b=="int"){return parseInt(a)}else{if(b=="double"||b=="float"){return parseFloat(a)}else{if(b=="bool"){return(a=="1"||a=="true")}else{if(b=="wkt"){return WKT(a)}else{if(b=="date"){if(a==""){return null}a=a.replace(/00:00:00.0/,"");a=a.replace(/-/g,"/");a=new Date(a);if((a+"")=="NaN"){return null}return a}else{if(b=="string"){return a}else{return a}}}}}}}function deepCloneJSON(e){if(e==null){return e}var b=null;var c=getDataType(e);if(c=="associative array"){b=[];for(var d in e){b[d]=deepCloneJSON(e[d])}return b}else{if(c=="array"){b=[];for(var a=0;a<e.length;a++){b.push(deepCloneJSON(e[a]))}return b}else{return e}}}function getDataType(d){if(d==null){return null}var a=typeof(d);if(a.indexOf("object")<0){return a}try{for(var c in d){if(c!=null&&d[c]!=null){return"associative array"}break}}catch(b){}if(d.length>0){if(d[0]!=null){return"array"}}return a}function OrderedHashtable(){this._columnNames=[];this._columnNameIndices=[];this._fieldArray=[];this._dataTypes=[];this.setByName=function(a,c,b){if(a!=null){a=(""+a).toUpperCase()}this._fieldArray[a]=c;if(b&&this._dataTypes[a]==null){if(b=="wkt"){this._dataTypes[a]="geometry"}else{this._dataTypes[a]=b}}if(this._columnNameIndices[a]==null){this._columnNameIndices[a]=this._columnNames.length;this._columnNames.push(a)}};this.getByName=function(a){if(a!=null){a=(""+a).toUpperCase()}return this._fieldArray[a]};this.getDataTypeByName=function(a){return this._dataTypes[a]};this.clear=function(){this._fieldArray=[];this._columnNameIndices=[];this._columnNames=[]};this.getCount=function(){return this._columnNames.length};this.contains=function(a){if(a!=null){a=a.toUpperCase()}return this._columnNameIndices[a]!=null};this.remove=function(b){if(b!=null){b=(""+b).toUpperCase()}var a;if((a=this._columnNameIndices[b])==null){throw new DMCException("GridControl.remove: trying to remove an inexisting field : "+b)}delete this._fieldArray[b];delete this._columnNameIndices[b];this._columnNames.splice(a,1);for(var d=a;d<this._columnNames.length;d++){var c=this._columnNames[d];this._columnNameIndices[c]=d}};this.removeAll=function(c){var d=[];for(var b=0;b<c.length;b++){var f=c[b];if(f!=null){f=(""+f).toUpperCase()}var g;if((g=this._columnNameIndices[f])==null){d.push(f);continue}this._fieldArray[f]=null;this._columnNameIndices[f]=null;this._columnNames.splice(g,1)}for(var a=0;a<this._columnNames.length;a++){var h=this._columnNames[a];this._columnNameIndices[h]=a}if(d.length>0){var e="GridControl.removeAll: failed to remove "+d.join()+"\n\twhen removing: "+c.join();throw new DMCException(e)}};this.getByIndex=function(a){return this._fieldArray[this._columnNames[a]]};this.getNameByIndex=function(a){return this._columnNames[a]};this.getNames=function(){var a=[];var b;for(b in this._fieldArray){a.push(b)}return a}}Dmp.Record=function(a,b){this.base=OrderedHashtable;this.base();this.FIELD_DELIMITER="+*+";this._resourceName=b;this._keyArray=a;this._properties=[];this.setResourceName=function(c){this._resourceName=c};this.getKeyField=function(){return this._keyArray[0]};this.getResourceName=function(){return this._resourceName};this.getRowNumber=function(){return this.getProperty("RowNumber")};this.setKeyField=function(c){this._keyArray=[c]};this.setCompositeKeyField=function(c){this._keyArray=c};this.getCompositeKeyField=function(){return this._keyArray};this.getKey=function(){var c=this.getByName(this._keyArray[0]);for(var d=1;d<this._keyArray.length;d++){c+=this.FIELD_DELIMITER+this.getByName(this._keyArray[d])}return c};this.getCompositeKey=function(){var d=[];for(var e=0;e<this._keyArray.length;e++){var f=this._keyArray[e];var c=this.getByName(f);d[f]=c}return d};this.clone=function(){var c=new Dmp.Record(this._keyArray,this._resourceName);for(var f in this._columnNames){c._columnNames[f]=this._columnNames[f]}for(var e in this._columnNameIndices){c._columnNameIndices[e]=this._columnNameIndices[e]}for(var d in this._fieldArray){c._fieldArray[d]=this._fieldArray[d]}c._keyArray=this._keyArray;return c};this.isSameRecord=function(c){for(var f in this._columnNames){if(c._columnNames[f]!=this._columnNames[f]){return false}}for(var e in this._columnNameIndices){if(c._columnNameIndices[e]!=this._columnNameIndices[e]){return false}}for(var d in this._fieldArray){if(c._fieldArray[d]!=this._fieldArray[d]){return false}}if(c._keyArray!=this._keyArray){return false}return true};this.getProperty=function(c){return this._properties[c]};this.removeProperty=function(c){delete this._properties[c]};this.hasProperty=function(c){return this._properties[c]!=null};this.setProperty=function(d,c){this._properties[d]=c};this.getProperties=function(){return this._properties}};if(typeof(Record)=="undefined"){Record=Dmp.Record}Dmp.RecordSet=function(c,g,e){var h=this;this.className="RecordSet";this._records=new OrderedHashtable();this._keyArray=c;this.base=Dmp.EventManager;this.base();var a="Cannot add additional records to collection";var b=2000;if(typeof(e)!=undefined&&e!=null){b=e}this.setExceedMaxRecordsMessage=function(j){a=j+" Exceeded maximum allowable records: "+b};this._listOfColumnNames=g;this.getKeyFields=function(){return this._keyArray};this.clear=function(){this._records=new OrderedHashtable()};this.setCompositeKeyField=function(j){this._keyArray=j};this.getColumnNames=function(){return this._listOfColumnNames};this.newRecord=function(j){return new Dmp.Record(this._keyArray,j)};this.setRecord=function(j,o){if(h.getCount()>b){alert(a);return}var k=j.getKey();var m=this._records.contains(k);var n=null;if(m&&!o){n=this._records.getByName(k).clone()}this._records.setByName(k,j);if(!o){if(m){var l=new Dmp.Event("recordUpdated",this,j);l.oldRecord=n;l.newRecord=j;this.notify(l)}else{this.notify(new Dmp.Event("recordAdded",this,j))}}return j};this.getRecord=function(j){var k=this._records.getByName(j);if(!k){return null}else{return k}};this.removeRecord=function(k,l){var j=this._records.getByName(k);if(!j){return}this._records.remove(k);if(!l){this.notify(new Dmp.Event("recordRemoved",this,j))}return j};this.clone=function(){var j=new Dmp.RecordSet(this._keyArray,this.getColumnNames());for(var k=0;k<this._records.getCount();k++){j.setRecord(this._records.getByIndex(k).clone())}return j};this.addRecordCollection=function(l){var k=new Array();var n=new Array();var o=true;for(var p=0;p<l.length;p++){var m=this._records.contains(l[p].getKey());var j=this.setRecord(l[p],o);if(m){n.push(j)}else{if(h.getCount()>b){alert(a);break}k.push(j)}}if(k.length>0){this.notify(new Dmp.Event("recordCollectionAdded",this,k))}return n};this.toArray=function(){var j=[];for(var k=0;k<this._records.getCount();k++){j.push(this._records.getByIndex(k))}return j};this.removeRecordCollection=function(k){var l=true;var m=[];for(var n=0;n<k.length;n++){if(this.getRecord(k[n])){var j=this.removeRecord(k[n],l);m.push(j)}}this.notify(new Dmp.Event("recordCollectionRemoved",this,m));return m};this.clearRecords=function(l){var j=this.toArray();if(!l){var k=null;k=new Dmp.Event("beforeRecordsCleared",this,j);this.notify(k);if(k.cancel==true){return false}}this._records.clear();if(!l){this.notify(new Dmp.Event("recordsCleared",this,j))}return true};this.getKeys=function(){var j=[];var l;for(l in this._records._fieldArray){j.push(l)}return j};this.toRecordArray=function(){var l=[];var j=this.getByCount();for(var k=0;k<j;k++){l.push(this.getByIndex(k))}return l};this.importData=function(D,G){this.clearRecords();if(!D){return}var o=[];var n=true;try{var r=[];this._keyArray=[];var w=D.selectSingleNode("Xml/Schema");var s=w.getAttribute("keys");if(s){this._keyArray=s.split(",")}var L=D.selectNodes("Xml/Schema/ElementType/AttributeType");for(var y=0;y<L.length;y++){var K=L[y];var p=K.getAttribute("basecolumn");r[p]=K.selectSingleNode("Datatype").getAttribute("type");if(s==null&&K.getAttribute("keycolumn")=="true"){this._keyArray.push(p)}}var z=D.selectNodes("Xml/Data/Row");for(var C=0;C<z.length;C++){var x=z[C];var v=null;var m=G;if(!m){var m=x.getAttribute("__resName");if(m==null){m="_importedFromFile"}}v=new Dmp.Record(this._keyArray,m);if(this._keyArray.length>1){v.setCompositeKeyField(this._keyArray)}for(var E in r){var l=x.getAttribute(E);if(l!=null){var J=r[E];l=tryParse(J,l)}v.setByName(E,XMLAbstraction.decode(l),J)}o.push(v);this.setRecord(v,n)}var u=D.selectNodes("Xml/Properties/Properties");for(var C=0;C<u.length;C++){var H=u[C];var v=null;var B=H.getAttribute("__key");if(B==null){continue}var F=this.getRecord(B);if(F==null){continue}var q=H.attributes;for(var A=0;A<q.length;A++){var t=q[A].nodeName;if(t=="RowNumber"||t=="__key"){continue}F.setProperty(t,XMLAbstraction.decode(H.getAttribute(t)))}}}catch(I){throw new Exception("RecordSet.importData(): malformatted xmlDOM: "+D==null?null:D.xml)}this.notify(new Dmp.Event("recordCollectionAdded",this,o))};this.exportData=function(){if(this.getCount()<=0){return null}var w=gGetDomFromString("");var E=w.createElement("Xml");var s=w.createElement("Schema");var n=w.createElement("Data");var D=w.createElement("Properties");E.appendChild(s);E.appendChild(n);E.appendChild(D);var B=[];for(var t=0;t<this._keyArray.length;t++){B[this._keyArray[t]]=true}s.setAttribute("keys",this._keyArray.join(","));var p=this.getByIndex(0);var A=[];for(var u=0;u<this.getCount();u++){var p=this.getByIndex(u);for(var t=0;t<p.getCount();t++){var m=p.getNameByIndex(t);var q=p.getByIndex(t);if(A[m]){continue}else{A[m]=true}var x=w.createElement("ElementType");x.setAttribute("name","row");var F=w.createElement("AttributeType");x.appendChild(F);F.setAttribute("name",m);F.setAttribute("number",t+1);F.setAttribute("basecolumn",m);if(B[m]){F.setAttribute("keycolumn","true")}var l;if(typeof q=="number"){l="float"}else{if(q==null||typeof q=="string"){l="string"}else{if(typeof q=="boolean"){l="bool"}else{if(d(q)){l="date"}else{if(q.TYPE=="POLYGON"||q.TYPE.indexOf("LINE")>=0||q.TYPE=="POINT"){l="wkt"}else{throw new DMCException("RecordSet.exportData(): not supported value type : "+q)}}}}}var C=w.createElement("Datatype");C.setAttribute("type",l);F.appendChild(C);s.appendChild(x)}}for(var t=0;t<this.getCount();t++){var p=this.getByIndex(t);var o=w.createElement("Row");for(var u=0;u<p.getCount();u++){o.setAttribute(p.getNameByIndex(u),XMLAbstraction.encode(""+p.getByIndex(u)))}o.setAttribute("__resName",p.getResourceName());n.appendChild(o)}for(var t=0;t<this.getCount();t++){var p=this.getByIndex(t);var k=p.getProperties();var z=null;for(var y in k){if(y=="RowNumber"){continue}if(z==null){z=w.createElement("Properties")}z.setAttribute(y,XMLAbstraction.encode(k[y]))}if(z==null){continue}z.setAttribute("__key",p.getKey());D.appendChild(z)}return E};function f(k){var j=/^\s+$/;return((k==null)||(k.length==0)||j.test(k))}function d(j){var k=new Date(j);return !f(j)&&!isNaN(k)}this.getCount=function(){return this._records.getCount()};this.getByIndex=function(j){return this._records.getByIndex(j)};this.getEmptyRecordSet=function(){return new Dmp.RecordSet(this._keyArray,this._listOfColumnNames)}};if(typeof(RecordSet)=="undefined"){RecordSet=Dmp.RecordSet}if(typeof(Dmp.Utils)=="undefined"){Dmp.Utils=new Object()}Dmp.Utils.pause=function(a){var b=window.showModalDialog("../AJAX-Spring/Util/_dmcsleepWindow.html",a,"dialogLeft:2000px;dialogTop:2000px;dialogHeight:1px;dialogWidth:1px;")};if(typeof(pause)=="undefined"){pause=Dmp.Utils.pause}function gSleep(a){try{var b=new XMLHttpRequest();b.open("GET","someFakeDocument.xml",false);b.send("")}catch(c){}}function gLoadJSON(g,h,d,e,f){function c(){}var a=null;if(f){a=f}else{a=getGUID()}_gDMCObserverLounge[a]=h;var b=g;if(g.indexOf("?")>0){b+="&"}else{b+="?"}b+='obsId=_gDMCObserverLounge["'+a+'"]';b+="&obsSuccessMethod="+d;b+="&obsErrorMethod="+e;b+="&output=JSON";_gDmcLoadScript(b,c,f)}var _gDMCLOGIN_URL="http://maps.digitalmapcentral.com/production/init";function ProcessError(a){if(a.indexOf("User not found")>=0){document.location.href=_gDMCLOGIN_URL;return}alert(a)}var _gDMCObserverLounge=new Array();function _gDMCNotifyJSON(obsID){var observer=_gDMCObserverLounge[obsID];if(observer==null){observer=eval(obsID)}return observer}function _gDmcLoadScript(a,c,b){if(document.all){_gDmcLoadScriptIE(a,c,b)}else{_gDmcLoadScriptMOZILLA(a,c,b)}}function _gDmcLoadScriptMOZILLA(e,h,c){var a=document.getElementsByTagName("head").item(0);var g=document.createElement("script");g.setAttribute("language","JavaScript1.2");g.setAttribute("src",e);if(c){g.setAttribute("id",c)}var d=0;if(h){g.addEventListener("load",h,false)}else{function b(){d=100}g.addEventListener("load",b,false)}a.appendChild(g);if(!h){try{while(d<50){gSleep(200);d++}}catch(f){}}}function _gDmcLoadScriptIE(c,f,e){var a=document.getElementsByTagName("head").item(0);var d=document.createElement("script");d.setAttribute("src",c);if(e){d.setAttribute("id",e)}if(f==null){if(d.readyState!="loaded"){var b=0;d.onreadystatechange=function(){if(this.readyState=="loaded"){d.onreadystatechange=null;b=100}};while(b<50&&d.readyState!="loaded"&&d.readyState!="complete"){Dmp.Utils.pause(100);b++}}}else{if(d.readyState=="loaded"||d.readyState=="complete"){f()}else{if(d.readyState!="loaded"){d.onreadystatechange=function(){if(this.readyState=="loaded"){f();d.onreadystatechange=null}}}else{alert("Cannot load data url:"+c)}}}a.appendChild(d)}function _gDmcRemoveScriptTagById(c){var a=document.getElementsByTagName("head").item(0);var b=document.getElementById(c);if(b){a.removeChild(b);return}else{}return false}if(typeof(Dmp.Geometry)=="undefined"){Dmp.Geometry=new Object()}function DMCtoVEGeometry(g,f){if(!f){f=g}if(!f.TYPE){throw new DMCException("DMCtoVEGeometry: input is not a DMC javascript geometry")}try{var h=f.getPoints();var d=[];for(var c=0;c<h.length;c++){d.push(new VELatLong(h[c].getY(),h[c].getX()))}if(f.TYPE=="POLYGON"||f.TYPE=="BOUNDS"){return new VEShape(VEShapeType.Polygon,d)}else{if(f.TYPE=="CIRCLE"){var a=new VEShape(VEShapeType.Pushpin,d[0]);return a}else{if(f.TYPE=="LINESTRING"){return new VEShape(VEShapeType.Polyline,d)}else{if(f.TYPE=="POINT"){return new VEShape(VEShapeType.Pushpin,d)}}}}}catch(b){}throw new DMCException("DMCtoVEGeometry: input is an not a DMC javascript geometry")}function DMCPoint3D(a,b,c){this.x=a;this.y=b;this.z=c;this.dot=function(d){return this.x*d.x+this.y*d.y+this.z*d.z}}function DMCBounds(b){this.TYPE="BOUNDS";this.xMin;this.yMin;this.xMax;this.yMax;if(b&&b.length>0){this.xMin=this.xMax=b[0].x;this.yMin=this.yMax=b[0].y;for(var a=1;a<b.length;a++){if(b[a].x<this.xMin){this.xMin=b[a].x}else{if(b[a].x>this.xMax){this.xMax=b[a].x}}if(b[a].y<this.yMin){this.yMin=b[a].y}else{if(b[a].y>this.yMax){this.yMax=b[a].y}}}}this.setBounds=function(c,d,e,f){this.xMin=c;this.yMin=d;this.xMax=e;this.yMax=f};this.min=function(){return new DMCPoint(this.xMin,this.yMin)};this.getMin=this.min;this.max=function(){return new DMCPoint(this.xMax,this.yMax)};this.getMax=this.max;this.equals=function(c){return c.xMin==this.xMin&&c.xMax==this.xMax&&c.yMin==this.yMin&&c.yMax==this.yMax};this.contains=function(c){return c.x>=this.xMin&&c.x<=this.xMax&&c.y>=this.yMin&&c.y<=this.yMax};this.containsBounds=function(c){return c.xMin>=this.xMin&&c.xMax<=this.xMax&&c.yMin>=this.yMin&&c.yMax<=this.yMax};this.intersects=function(c){if((!((this.xMax<c.xMin)||(this.xMin>c.xMax)))&&(!((this.yMax<c.yMin)||(this.yMin>c.yMax)))){return true}return false};this.extend=function(c){if(c.x>this.xMax){this.xMax=c.x}else{if(c.x<this.xMin){this.xMin=c.x}}if(c.y>this.yMax){this.yMax=c.y}else{if(c.y<this.yMin){this.yMin=c.y}}};this.intersection=function(c){var d,e,f,g;var h=0;if(c.xMin>=this.xMin&&c.xMin<=this.xMax){d=c.xMin;++h}if(c.xMax>=this.xMin&&c.xMax<=this.xMax){f=c.xMax;++h}if(h<2){if(this.xMin>=c.xMin&&this.xMin<=c.xMax){d=this.xMin;++h}if(this.xMax>=c.xMin&&this.xMax<=c.xMax){f=this.xMax;++h}}if(h<2){return new DMCBounds([new DMCPoint(0,0),new DMCPoint(0,0)])}h=0;if(c.yMin>=this.yMin&&c.yMin<=this.yMax){e=c.yMin;++h}if(c.yMax>=this.yMin&&c.yMax<=this.yMax){g=c.yMax;++h}if(h<2){if(this.yMin>=c.yMin&&this.yMin<=c.yMax){e=this.yMin;++h}if(this.yMax>=c.yMin&&this.yMax<=c.yMax){g=this.yMax;++h}}if(h<2){return new DMCBounds([new DMCPoint(0,0),new DMCPoint(0,0)])}return new DMCBounds([new DMCPoint(d,e),new DMCPoint(f,g)])};this.getSouthEast=function(){return new DMCPoint(this.xMax,this.yMin)};this.getSouthWest=function(){return new DMCPoint(this.xMin,this.yMin)};this.getNorthEast=function(){return new DMCPoint(this.xMax,this.yMax)};this.getNorthWest=function(){return new DMCPoint(this.xMin,this.yMax)};this.toSpan=function(){return new DMCPoint(this.xMax-this.xMin,this.yMax-this.yMin)};this.isValidLat=function(){return this.yMin<=-90&&this.yMax>=90};this.isValidLng=function(){return this.max<=-180&&this.yMax>=180};this.isEmpty=function(){return this.xMin>=this.xMax||this.yMin>=this.yMax};this.getCenter=function(){return new DMCPoint((this.xMax+this.xMin)/2,(this.yMax+this.yMin)/2,true)};this.getPoints=function(){return[new DMCPoint(this.xMin,this.yMin),new DMCPoint(this.xMin,this.yMax),new DMCPoint(this.xMax,this.yMax),new DMCPoint(this.xMax,this.yMin),new DMCPoint(this.xMin,this.yMin)]};this.toString=function(){var c=new DMCPolygon(this.getPoints());return c.toString()}}function DMCPoint(a,b,c){this.TYPE="POINT";this.x=a;this.y=b;if(!c){this.y=Math.max(-90,this.y);this.y=Math.min(90,this.y);this.x=Math.max(-180,this.x);this.x=Math.min(180,this.x)}this.toString=function(){return"POINT("+this.x+" "+this.y+")"};this.getX=function(){return this.x};this.getY=function(){return this.y};this.setX=function(d){this.x=d};this.setY=function(d){this.y=d};this.getLat=function(){return this.y};this.getLng=function(){return this.x};this.getPoints=function(){return[this]};this.setPoints=function(d){var e=null;if(typeof(d.length)!="undefined"&&d.length>0){e=d[0]}else{e=d}if(e!=null){this.x=e.x;this.y=e.y}};this.getLatRadians=function(){return this.y*Math.PI/180};this.getLngRadians=function(){return this.x*Math.PI/180};this.equals=function(d){return this.y==d.y&&this.x==d.x};this.intersects=function(e){if(e==null){throw new DMCException("DMCPoint.intersects can not take a null parameter")}if(e.TYPE=="POINT"){return this.equals(e)}if(e.TYPE=="POLYGON"||e.TYPE=="CIRCLE"){var f=e.contains(this);return f}if(e.TYPE=="BOUNDS"){var f=e.contains(this);return f}if(e.TYPE=="LINESTRING"){var h=false;var d=Math.EPSILON;for(var g=0;g<e.getVertexCount()-1;g++){var h=pointCloseToSegment(e.getVertex(g),e.getVertex(g+1),this,d);if(h){break}}return h}throw new DMCException("Other geometry types no supported.")};this.getCentroid=function(){return new DMCPoint(this.x,this.y,c)};this.getCenter=function(){return new DMCPoint(this.x,this.y,c)};this.getHandles=function(){var d=[];var e={TYPE:"WHOLE",INDEX:0,GEOMETRY:this};d.push(e);return d};this.modifyByHandle=function(e,d){this.x=d.x;this.y=d.y};this.projectToPixels=function(d){return d.latLngToPixel(this)}}function _pointArray1DtoPointArray(a){var c=[];for(var b=0;b<a.length;b+=2){c.push(new DMCPoint(a[b],a[b+1]))}return c}function DMCPoly(a,b){this.points=a;if(!this.points){this.points=[]}this.TYPE=b;var c=this;this.getVertexCount=function(){return this.points.length};this.getVertex=function(d){return this.points[d]};this.getPoints=function(){return this.points};this.setPoints=function(d){this.points=d};this.getBounds=function(){return new DMCBounds(this.points)};this.getArea=function(){return 0};this.getLength=function(){return _getLength(this.points)};this.intersects=function(d){throw new DMCException("Intersects implemenation is not supported to DMCLineString")};this.getHandles=function(){var f=[];var d=this.points.length;for(var h=0;h<(d-1);h++){var j=this.points[h];var g=this.points[h+1];var e=new DMCPoint((j.x+g.x)/2,(j.y+g.y)/2,true);f.push({TYPE:"INSERT_VERTEX",PT_INDEX:h,INDEX:f.length-1,GEOMETRY:e})}for(var h=0;h<d;h++){var k=new DMCPoint(this.points[h].x,this.points[h].y);f.push({TYPE:"VERTEX",PT_INDEX:h,INDEX:f.length-1,GEOMETRY:k})}f.push({TYPE:"WHOLE",INDEX:f.length-1,GEOMETRY:this.getClone()});return f};this.modifyByHandle=function(h,l,f){var j=h.PT_INDEX;if(h.TYPE=="VERTEX"){var g=this.points[j];g.x=l.x;g.y=l.y;if(this.TYPE=="POLYGON"){if(j==0){var g=this.points[this.points.length-1];g.x=l.x;g.y=l.y}else{if(j==this.points.length-1){var g=this.points[0];g.x=l.x;g.y=l.y}}}}else{if(h.TYPE=="WHOLE"){var e=l.x-f.x;var k=l.y-f.y;for(var d=0;d<this.points.length;d++){this.points[d].x+=e;this.points[d].y+=k}}else{if(h.TYPE=="INSERT_VERTEX"){return c.insertVertex(h.GEOMETRY,j+1)}}}};this.insertVertex=function(f,h){var d=this.points.length;if(h<0||h>d){return false}var e=[];for(var g=0;g<d;g++){if(g==h){e.push(f)}e.push(this.points[g])}this.points=e;return true};this.projectToPixels=function(f){var d=[];for(var e=0;e<this.points.length;e++){d.push(f.latLngToPixel(this.points[e]))}return new DMCLineString(d)}}function DMCLineString(a){this.base=DMCPoly;this.base(a,"LINESTRING");this.toString=function(){var b=this.TYPE+"(";for(var c=0;c<this.points.length;c++){if(c!=0){b+=","}b+=this.points[c].x+" "+this.points[c].y}b+=")";return b};this.getCenter=function(){var b=a.length;var d;var c=0;var e=0;for(d in a){c+=a[d].getX();e+=a[d].getY()}if((a[0].getX()==a[b-1].getX())&&(a[0].getY()==a[b-1].getY())){b=b-1;c-=a[0].getX();e-=a[0].getY()}return new DMCPoint(c/b,e/b)};this.getClone=function(){var b=[];for(var c=0;c<this.points.length;c++){b.push(new DMCPoint(this.points[c].x,this.points[c].y))}return new DMCLineString(b)}}DMCLineString.prototype=new DMCPoly();function DMCPolygon(a){this.base=DMCPoly;this.base(a,"POLYGON");this.getClone=function(){var b=[];for(var c=0;c<this.points.length;c++){b.push(new DMCPoint(this.points[c].x,this.points[c].y))}return new DMCPolygon(b)};this.toString=function(){var b="POLYGON((";for(var c=0;c<this.points.length;c++){if(c!=0){b+=","}b+=this.points[c].x+" "+this.points[c].y}b+="))";return b};this.getArea=function(){var e=this.points;var b=e.length;var h=new Array();var c=new Array();var f=0;var g=Math.floor((e[0].getX()+180)/6)+1;for(var d=0;d<b;d++){LatLonToUTMXY(DegToRad(e[d].getY()),DegToRad(e[d].getX()),g,c);h[d]=new DMCPoint(c[0],c[1],true)}for(var d=0;d<b-1;d++){f+=h[d].getX()*h[d+1].getY()-h[d].getY()*h[d+1].getX()}delete h;delete c;return Math.abs(0.5*f)};this.getAreaForInput=function(c){if((typeof(c)=="undefined")||(c==null)){return 0}var d=c;var b=d.length;var e=0;for(var f=0;f<b-1;f++){e+=d[f].getX()*d[f+1].getY()-d[f].getY()*d[f+1].getX()}return Math.abs(0.5*e)};this.getCenter=function(){var c=this.getCentroid();if(c==null){return null}if(this.contains(c)){return c}var b=this.adjustCenter(this.points,c);return b};this.getAveragePosition=function(){if(this.points==null){return null}var b=this.points.length;if(b<2){return null}var c=0;var e=0;for(var d=0;d<b-1;d++){c+=this.points[d].getX();e+=this.points[d].getY()}return new DMCPoint(c/(b-1),e/(b-1),true)};this.getCentroid=function(){if(this.points==null){return null}if(this.points.length<2){return null}var c=1e-20;var k=this.getAreaForInput(this.points);if(k<c){var f=this.getAveragePosition();return f}var d=this.points.length-1;var o=this.points[0].getX();var n=this.points[0].getY();var r=this.points[0].getY();var h=this.points[0].getY();var t=this.points[0].getX();var j=this.points[0].getX();for(var b=0;b<=d;b++){if(this.points[b].getY()>r){r=this.points[b].getY()}else{if(this.points[b].getY()<h){h=this.points[b].getY()}}if(this.points[b].getX()>t){t=this.points[b].getX()}else{if(this.points[b].getX()<j){j=this.points[b].getX()}}this.points[b].setX(this.points[b].getX()-o);this.points[b].setY(this.points[b].getY()-n)}var s=0;var q=0;var e;for(var b=0;b<d;b++){e=(this.points[b].getX()*this.points[b+1].getY()-this.points[b+1].getX()*this.points[b].getY());s+=((this.points[b].getX()+this.points[b+1].getX())*e);q+=((this.points[b].getY()+this.points[b+1].getY())*e)}var p=(0.166666666666667)*(1/k);s*=p;q*=p;for(var b=0;b<=d;b++){this.points[b].setX(this.points[b].getX()+o);this.points[b].setY(this.points[b].getY()+n)}s+=o;q+=n;var g=new DMCPoint(s,q,true);if((s<j)||(s>t)||(q<h)||(q>r)){g=this.getAveragePosition()}return g};this.adjustCenter=function(v,c){if((typeof(c)=="undefined")||(c==null)){return null}if((typeof(v)=="undefined")||(v==null)){return new DMCPoint(c.getX(),c.getY(),true)}var q=1e-20;var E=v.length;if(E<4){return new DMCPoint(c.getX(),c.getY(),true)}var m=E-1;var A=-1e+20;var b=1e+20;for(var h=0;h<=m;h++){if(v[h].getY()>A){A=v[h].getY()}if(v[h].getY()<b){b=v[h].getY()}}var d=c.getX();var p=c.getY();var e=new Array();var n=new Array();var B=0;if((p>b+q)&&(p<A-q)){B=this.horizontalSegments(v,e,n,p,0)}else{return new DMCPoint(d,p,true)}var w=-1;var D=1e+20;var y=-1;for(var h=0;h<B;h++){var z=Math.abs(n[h]-d);if(z<D){D=z;y=n[h];w=h}}if(w>=0){var k=new DMCPoint(y,p,true);return k}var f=4;var r=new Array(f+f);var g=A-p;if(g<q){g=0}var C=b-p;if(C>-q){C=0}var o=g/f;var u=C/f;var s=o;var x=u;for(var h=0;h<f;h++){r[h+h]=p+x;r[h+h+1]=p+s;s+=o;x+=u}for(var h=0;h<f+f;h++){var B=0;if((r[h]>b+q)&&(r[h]<A-q)){B=this.horizontalSegments(v,e,n,r[h],0)}var w=-1;var D=1e+20;var y=-1;for(var t=0;t<B;t++){var z=Math.abs(n[t]-d);if(z<D){D=z;y=n[t];w=t}}if(w>=0){var k=new DMCPoint(y,r[h],true);return k}}return new DMCPoint(d,p,true)};this.getCenterForPlacement=function(F,I,b){if((typeof(F)=="undefined")||(F==null)){return null}if(I<0){I=0}if(b<0){b=0}var p=1e-20;var d=F.length;if(d<4){return null}var c=new DMCPolygon(F);var v=this.getAreaForInput(F);if(v<p){var C=c.getAveragePosition();return C}var B=d-1;var o=F[0].getY();var A=F[0].getY();var E=F[0].getX();var q=F[0].getX();for(var G=0;G<=B;G++){if(F[G].getY()>o){o=F[G].getY()}else{if(F[G].getY()<A){A=F[G].getY()}}if(F[G].getX()>E){E=F[G].getX()}else{if(F[G].getX()<q){q=F[G].getX()}}}var m=c.getCentroid();var r=m.getX();var L=m.getY();var w=1.5;var n=false;var s=new Array();var J=new Array();var M=0;if((L>A+b/2+p)&&(L<o-b/2-p)){M=this.horizontalSegments(F,s,J,L,b)}else{n=true}var O=false;var N=-1;var x=-1;for(var G=0;G<M;G++){if(s[G]>N){N=s[G];x=G}if(s[G]>w*I){r=J[G];n=true;break}}var y=-10000000000;var H=-10000000000;var D=L;if(x>=0){y=N;H=J[x]}var K=8;if(!n){if(N>w*I){r=J[x];O=true}else{var g=new Array(K+K);var e=o-L;if(e<p){e=0}var t=A-L;if(t>-p){t=0}var z=e/K;var u=t/K;var h=z;var P=u;for(var G=0;G<K;G++){g[G+G]=L+P;g[G+G+1]=L+h;h+=z;P+=u}for(var G=0;G<K+K;G++){var M=0;if((g[G]>A+b/2+p)&&(g[G]<o-b/2-p)){M=this.horizontalSegments(F,s,J,g[G],b)}var N=-1;var x=-1;for(var f=0;f<M;f++){if(s[f]>N){N=s[f];x=f}}if(N>w*I){r=J[x];L=g[G];O=true;break}if(N>y){y=N;H=J[x];D=g[G]}}if((!O)&&(y>I)){r=H;L=D}delete g}}else{O=true}delete s;delete J;var k=new DMCPoint(r,L,true);if((r<q)||(r>E)||(L<A)||(L>o)){k=c.getAveragePosition()}return k};this.horizontalSegments=function(n,d,l,b,c){var q=0;var t=n.length;if(t<2){return 0}var p=1e-08;var g=c;if(g<p){g=p}var k=new Array();var h=0;for(var j=0;j<t-1;j++){var f=n[j].getY();var m=n[j+1].getY();var e=false;if((Math.abs(f-b)<g)&&(Math.abs(m-b)<g)){delete k;return 0}if(f<(b+p)){if(m>b){e=true}}else{if(f>(b-p)){if(m<b){e=true}}}if(e==true){var r=n[j].getX();var s=n[j+1].getX();var o=r+((b-f)*(s-r)/(m-f));k[h]=o;h++}}if(h%2==1){alert("Odd number of intersections!!")}if(h>0){k.sort(sortNumber);q=0;for(var j=0;j<h-1;j=j+2){d[q]=k[j+1]-k[j];l[q]=(k[j+1]+k[j])/2;q++}}delete k;return q};this.intersects=function(b){if(b==null){throw new DMCException("DMCPolygon.intersects can not take a null parameter")}if(b.TYPE=="POINT"){return this.contains(b)}else{if(b.TYPE=="BOUNDS"){var c=this.getBounds();return b.intersects(c)}}throw new DMCException("Only Point in polygon is supported")};this.contains=function(h){if(h==null){throw new DMCException("DMCPolygon.intersects can not take a null parameter")}if(h.TYPE!="POINT"){throw new DMCException("DMCPolygon.intersects expects only point geometry")}var g=0;var f=0;var b=this.points.length;var e=b-1;for(f,e;f<b;e=f++){var d=h.getY();var c=h.getX();if((((this.points[f].getY()<=d)&&(d<this.points[e].getY()))||((this.points[e].getY()<=d)&&(d<this.points[f].getY())))&&(c<(this.points[e].getX()-this.points[f].getX())*(d-this.points[f].getY())/(this.points[e].getY()-this.points[f].getY())+this.points[f].getX())){g=!g}}return g};this.getVertexCount=function(){return this.points.length};this.getVertex=function(b){return this.points[b]};this.isClockWise=function(){if((this.points==null)||(this.points.length<4)){return false}var h=false;var b=this.points.length;var f=this.points[0].getY();var c=0;for(var g=1;g<b-1;g++){if(this.points[g].getY()<f){f=this.points[g].getY();c=g}}var e=this.points[(c+b-2)%(b-1)].getX();var d=this.points[(c+1)%(b-1)].getX();if(e>d){h=true}else{h=false}return h}}DMCPolygon.prototype=new DMCPoly();function DMCCircle(a,b){this.TYPE="CIRCLE";this.dmcMap=b;this.points=new Array();this.points[0]=new DMCPoint(a[0].getX(),a[0].getY(),true);this.points[1]=new DMCPoint(a[1].getX(),a[1].getY(),true);this.getVertexCount=function(){return this.points.length};this.getVertex=function(c){return this.points[c]};this.calculatePolygon=function(){if(this.points==null||this.points.length<1){return null}var r=false;if(this.points[0].getLat()<0){r=true}var q=Math.floor((this.points[0].getX()+180)/6)+1;var k=new Array();var m=null;if(this.dmcMap!=null){m=new Array();m[0]=new DMCPoint(this.points[0].getX(),this.points[0].getY(),true);m[1]=new DMCPoint(this.points[1].getX(),this.points[1].getY(),true);for(var n=0;n<2;n++){var t=new Array();LatLonToUTMXY(DegToRad(m[n].getY()),DegToRad(m[n].getX()),q,t);m[n].setX(t[0]);m[n].setY(t[1])}}else{m=this.points}var l=100;var e=(Math.PI*2)/l;var k=new Array(l+1);var g=m[1].x-m[0].x;var o=m[1].y-m[0].y;var s=Math.sqrt(g*g+o*o);var p=m[0];var j=(m[1].getY()-m[0].getY())/s;var d=(m[1].getX()-m[0].getX())/s;k[0]=new DMCPoint(s,0,true);k[l]=new DMCPoint(s,0,true);var u=0;for(var n=1;n<l;n++){u+=e;var v=s*Math.cos(u);var c=s*Math.sin(u);k[n]=new DMCPoint(v,c,true)}for(var n=0;n<=l;n++){var v=k[n].getX()*d-k[n].getY()*j;var c=k[n].getY()*d+k[n].getX()*j;k[n].setX(p.x+v);k[n].setY(p.y+c)}if(this.dmcMap!=null){for(var n=0;n<=l;n++){var h=new Array();UTMXYToLatLon(k[n].getX(),k[n].getY(),q,r,h);k[n].setX(RadToDeg(h[1]));k[n].setY(RadToDeg(h[0]))}}var f=new DMCPolygon(k);return f};this.polygon=this.calculatePolygon();this.getCenter=function(){return new DMCPoint(this.points[0].getX(),this.points[0].getY(),true)};this.intersects=function(c){if(c==null){throw new DMCException("DMCCircle.intersects can not take a null parameter")}if(c.TYPE=="POINT"){return this.contains(c)}else{if(c.TYPE=="BOUNDS"){var d=this.getBounds();return c.intersects(d)}}throw new DMCException("Only Point in circle is supported")};this.contains=function(j){if(j==null){throw new DMCException("DMCCircle.intersects can not take a null parameter")}if(j.TYPE!="POINT"){throw new DMCException("DMCPolygon.intersects expects only point geometry")}if(this.points==null||this.points.length<1){return false}var n=null;var e=j;if(this.dmcMap!=null){n=new Array();n[0]=new DMCPoint(this.points[0].getX(),this.points[0].getY(),true);n[1]=new DMCPoint(this.points[1].getX(),this.points[1].getY(),true);n[2]=new DMCPoint(j.getX(),j.getY(),true);for(var c=0;c<3;c++){var l=Math.floor((n[c].getX()+180)/6)+1;var m=new Array();LatLonToUTMXY(DegToRad(n[c].getY()),DegToRad(n[c].getX()),l,m);n[c].setX(m[0]);n[c].setY(m[1])}e=n[2]}else{n=this.points}var h=n[1].getX()-n[0].getX();var o=n[1].getY()-n[0].getY();var d=h*h+o*o;var k=e.getX()-n[0].getX();var f=e.getY()-n[0].getY();var g=k*k+f*f;if(g<=d){return true}else{return false}};this.getPoints=function(){return this.points};this.clearBoundPoly=function(){this.polygon=null};this.getBoundPoly=function(){if(this.polygon==null){this.polygon=this.calculatePolygon()}return this.polygon};this.getBounds=function(){if(this.points==null||this.points.length!=2){throw new DMCException("DMCCircle: do not get bounds of an empty circle!")}var e=false;if(this.points[0].getLat()<0){e=true}var k=Math.floor((this.points[0].getX()+180)/6)+1;var m=null;if(this.dmcMap!=null){m=new Array();m[0]=new DMCPoint(this.points[0].getX(),this.points[0].getY(),true);m[1]=new DMCPoint(this.points[1].getX(),this.points[1].getY(),true);for(var c=0;c<2;c++){var l=new Array();LatLonToUTMXY(DegToRad(m[c].getY()),DegToRad(m[c].getX()),k,l);m[c].setX(l[0]);m[c].setY(l[1])}}else{m=this.points}var h=m[1].x-m[0].x;var n=m[1].y-m[0].y;var j=Math.sqrt(h*h+n*n);var f=new Array();f[0]=new DMCPoint(m[0].x+j,m[0].y,true);f[1]=new DMCPoint(m[0].x,m[0].y+j,true);f[2]=new DMCPoint(m[0].x-j,m[0].y,true);f[3]=new DMCPoint(m[0].x,m[0].y-j,true);if(this.dmcMap!=null){for(var c=0;c<4;c++){var d=new Array();UTMXYToLatLon(f[c].getX(),f[c].getY(),k,e,d);f[c].setX(RadToDeg(d[1]));f[c].setY(RadToDeg(d[0]))}}var g=new DMCBounds(f);return g};this.getBoundsInPixel=function(){if(this.points==null||this.points.length!=2){throw new DMCException("DMCCircle: do not get bounds of an empty circle!")}var e=false;if(this.points[0].getLat()<0){e=true}var k=Math.floor((this.points[0].getX()+180)/6)+1;var m=null;if(this.dmcMap!=null){m=new Array();m[0]=new DMCPoint(this.points[0].getX(),this.points[0].getY(),true);m[1]=new DMCPoint(this.points[1].getX(),this.points[1].getY(),true);for(var c=0;c<2;c++){var l=new Array();LatLonToUTMXY(DegToRad(m[c].getY()),DegToRad(m[c].getX()),k,l);m[c].setX(l[0]);m[c].setY(l[1])}}else{m=this.points}var h=m[1].x-m[0].x;var n=m[1].y-m[0].y;var j=Math.sqrt(h*h+n*n);var f=new Array();f[0]=new DMCPoint(m[0].x+j,m[0].y,true);f[1]=new DMCPoint(m[0].x,m[0].y+j,true);f[2]=new DMCPoint(m[0].x-j,m[0].y,true);f[3]=new DMCPoint(m[0].x,m[0].y-j,true);if(this.dmcMap!=null){for(var c=0;c<4;c++){var d=new Array();UTMXYToLatLon(f[c].getX(),f[c].getY(),k,e,d);f[c].setX(RadToDeg(d[1]));f[c].setY(RadToDeg(d[0]))}this.dmcMap.latLngPointsToPixelPoints(f)}var g=new DMCBounds(f);return g};this.getArea=function(){if(this.points==null||this.points.length!=2){return 0}var l=this.points;var d=l.length;var k=new Array();var j=new Array();var e=0;var h=Math.floor((l[0].getX()+180)/6)+1;for(var c=0;c<d;c++){LatLonToUTMXY(DegToRad(l[c].getY()),DegToRad(l[c].getX()),h,j);k[c]=new DMCPoint(j[0],j[1],true)}var g=k[1].getX()-k[0].getX();var f=k[1].getY()-k[0].getY();var e=Math.PI*(g*g+f*f);delete k;delete j;return e};this.getLength=function(){if(this.points==null||this.points.length!=2){return 0}var m=this.points;var d=m.length;var l=new Array();var k=new Array();var e=0;var j=Math.floor((m[0].getX()+180)/6)+1;for(var c=0;c<d;c++){LatLonToUTMXY(DegToRad(m[c].getY()),DegToRad(m[c].getX()),j,k);l[c]=new DMCPoint(k[0],k[1],true)}var g=l[1].getX()-l[0].getX();var f=l[1].getY()-l[0].getY();var h=2*Math.PI*Math.sqrt(g*g+f*f);delete l;delete k;return h};this.getCentroid=function(){return new DMCPoint(this.points[0].getX(),this.points[0].getY())};this.toString=function(){if(this.points==null||this.points.length<2){return""}var c="CIRCLE(("+this.points[0].x+" "+this.points[0].y+","+this.points[1].x+" "+this.points[1].y+"))";return c}}function WKT(c){try{var h=new RegExp(/(?:\()([^)(]*)(?:\))/g);var a=h.exec(c);var f=null;if(a!=null&&a.length>0){f=a[0].substring(1,a[0].length-1)}h=new RegExp(/[^(]*/g);var j=h.exec(c);var g=null;if(j!=null&&j.length>0){g=j[0].replace(/ /,"")}if(f==null||f==""||g==null||g==""){return null}var b=__parseWKTPointsString(f);if(g=="POINT"){if(b.length!=2){throw null}return new DMCPoint(b[0],b[1])}else{if(g=="LINESTRING"){if(b.length<4){throw null}return new DMCLineString(_pointArray1DtoPointArray(b))}else{if(g=="POLYGON"||g=="MULTIPOLYGON"){if(b.length<4){throw null}return new DMCPolygon(_pointArray1DtoPointArray(b))}else{if(g=="CIRCLE"){if(b.length<2){throw null}return new DMCCircle(_pointArray1DtoPointArray(b))}else{return null}}}}}catch(d){return null}}function __parseWKTPointsString(d){var e=d.split(",");var a=[];for(var b=0;b<e.length;b++){var c=e[b].split(" ");c=__deleteBlankStringFromArray(c);if(c.length!=2){throw"unsupported/malformatted wkt format:"+d}a.push(parseFloat(c[0]));a.push(parseFloat(c[1]))}return a}function __deleteBlankStringFromArray(f){var e=[];for(var c=0;c<f.length;c++){var d=true;var b=f[c].split(" ");for(var a=0;a<b.length;a++){if(b[a].length!=0){d=false;break}}if(!d){e.push(_trim(f[c]))}}return e}function _lTrim(a){return a.replace(/^\s*/,"")}function _rTrim(a){return a.replace(/\s*$/,"")}function _trim(a){return _rTrim(_lTrim(a))}function _getLength(h){var f=0;var b=h.length;var d=new Array();var g=new Array();var e=Math.floor((h[0].getX()+180)/6)+1;for(var a=0;a<b;a++){LatLonToUTMXY(DegToRad(h[a].getY()),DegToRad(h[a].getX()),e,d);g[a]=new DMCPoint(d[0],d[1],true)}for(var a=0;a<b-1;a++){var c=Math.pow((g[a].getX()-g[a+1].getX()),2)+Math.pow((g[a].getY()-g[a+1].getY()),2);f=f+Math.sqrt(c)}return f}function createPolygonFromEnvelope(a,b,c,d){var e=[new DMCPoint(a,b),new DMCPoint(c,b),new DMCPoint(c,d),new DMCPoint(a,d),new DMCPoint(a,b)];var f=new DMCPolygon(e);return f}function distanceBetweenLatLongs(h,f){var g=6372795.477598;var a=b(h);var d=b(f);var c=a.dot(d);var e=Math.acos(c);return g*e;function b(p){var n=p.getLatRadians();var l=p.getLngRadians();var m=Math.sin(n);var o=Math.cos(n);var j=o*Math.cos(l);var k=o*Math.sin(l);return new DMCPoint3D(j,k,m)}}Dmp.Geometry.distance=function(d,b){var e=d.x-b.x;var c=d.y-b.y;var a=Math.sqrt(e*e+c*c);return a};if(typeof(distance)=="undefined"){distance=Dmp.Geometry.distance}function sortNumber(c,d){return(c-d)}function pointCloseToSegment(g,k,l,h){var c=k.getX()-g.getX();var f=k.getY()-g.getY();var d=Math.sqrt(c*c+f*f);var e=l.getX()-g.getX();var n=l.getY()-g.getY();var j=e*e+n*n;if(d<Math.EPSILON){if(j<h*h){return true}else{return false}}else{var m=(c*e+f*n)/d;var b=j-m*m;if((m>=-h)&&(m<=d+h)&&(b<h*h)){return true}else{return false}}}function DMCtoGoogGeometry(a,b,l,j,d,k){if(!a.TYPE){throw new DMCException("DMCtoGoogGeometry: input is not a DMC javascript geometry")}try{var h=a.getPoints();var f=[];for(var g=0;g<h.length;g++){f.push(new GLatLng(h[g].getY(),h[g].getX()))}if(a.TYPE=="POINT"){return f[0]}else{if(a.TYPE=="BOUNDS"||a.TYPE=="POLYGON"){return new GPolygon(f,b,l,j,d,k)}else{if(a.TYPE.indexOf("LINE")>=0){return new GPolyline(f,b,l,j)}}}}catch(c){}throw new DMCException("DMCtoGoogGeometry: input is an not a DMC javascript geometry ("+a.TYPE+")")}function FixForFirefox2(){var c=0;var b="Firefox/";var a=navigator.userAgent.indexOf(b);if(a!=-1){c=parseFloat(navigator.userAgent.substring(a+b.length))}if(c>=1.5){Msn.Drawing.Graphic.CreateGraphic=function(e,d){return new Msn.Drawing.SVGGraphic(e,d)}}}function SetDMPKey(a){_DMP_KEY=a}var _G_COUNTER=0;var _DMP_KEY="user";var _OUTPUT_TYPE="PNG";var _G_DMP_SERVER_NAME="http://parcelstream.com";var G_NUM_SERVERS=4;var _G_MULTIDOMAIN_SERVER_NAME=new Array();for(var i=0;i<G_NUM_SERVERS;i++){_G_MULTIDOMAIN_SERVER_NAME[i]="t"+i}var _gExpectedFilter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='";function _gOverrideAppendChildIE7(e,d,b,a){if(e.tagName!="IMG"){return this._dmcAppendChild(e,d,b,a)}if(e.src.indexOf(_G_DMP_SERVER_NAME)<0&&!containsDomainName(e.src)){return this._dmcAppendChild(e,d,b,a)}var f=e.style.filter;if(f==null||f==""){return this._dmcAppendChild(e,d,b,a)}f+="";var c="alpha(opacity=100);";if(f.indexOf(c)>=0){e.style.filter=""}return this._dmcAppendChild(e,d,b,a)}function _gOverrideAppendChildIE6(e,l,a,j){if(e.tagName=="DIV"&&e.innerHTML==""){var d=e.style.filter;if(d!=null){d+="";if(d!=""){if(d.indexOf(_gExpectedFilter+_G_DMP_SERVER_NAME)>=0||containsDomainName(d,_gExpectedFilter,_gExpectedFilter.length)){var m=d.indexOf("http://");var b=d.indexOf("',",m);var f=d.substring(m,b);var h=false;if(f!=null&&f.toLowerCase().indexOf("png")>-1){h=true}if(h){var c=", alpha(opacity=100)";var g=""+e.style.filter;var k=g.split(c);if(k.length==2){e.style.filter=k[0]+k[1]}}else{var n=document.createElement("IMG");n.src=f;n.style.left=e.style.left;n.style.top=e.style.top;n.style.width=e.style.width;n.style.height=e.style.height;n.style.border=e.style.border;n.style.zIndex=e.style.zIndex;n.style.position=e.style.position;e=n}}}}}this._dmcAppendChild(e,l,a,j)}var _b_dmc_hasInitCalled=false;function gInitializeDMPLayers(b){if(_b_dmc_hasInitCalled){return}_b_dmc_hasInitCalled=true;if(document.all){var a=document.getElementById(b.ID).firstChild;if(a==null){alert("Error in DMP API. Please contact Digital Map Products Inc. Support.");return}a._dmcAppendChild=a.appendChild;if(navigator.userAgent.indexOf("MSIE 7.0")>=0){a.appendChild=_gOverrideAppendChildIE7}else{a.appendChild=_gOverrideAppendChildIE6}}}function SetParcelLayerVisibility(c,a){if(c==null){alert("Please pass Virtual Earth map instance as a parameter to the ToggleDMPParcelLayer() function. ");return}var b=c.parcelLayer;if(b){b.setVisible(a)}}function AddDMPParcelLayer(c,b){if(c==null){alert("Please pass Virtual Earth map instance as a parameter to the AddDMPParcelLayer() function. ");return}else{if(typeof(c.parcelLayer)!="undefined"){alert("This map already has a parcel layer defined in it. ");return}}gInitializeDMPLayers(c);var a=new TiledLayer(c,["Parcels"]);a.setMinZoomLevel(16);a.setMaxZoomLevel(19);a.setFormat("image/png");if(b){a.setZIndex(b)}a.initialize();c.parcelLayer=a}function containsDomainName(c,a,d){var b,f;if(a==null){a="";d=0}else{if(d==null||d<0){d=0}}for(var e=0;e<G_NUM_SERVERS;e++){f=_G_DMP_SERVER_NAME.substr(0,7)+_G_MULTIDOMAIN_SERVER_NAME[e]+"."+_G_DMP_SERVER_NAME.substr(7);if(d<a.length){b=a.substr(0,d)+f+a.substr(d)}else{b=a+f}if(c.toLowerCase().indexOf(b.toLowerCase())!=-1){return true}}return false}function GoogleTiledLayer(n,r,e){var h="http://t%2.parcelstream.com/";if(!e){e=h+"VEParcelTileServer.aspx"}var g=n;var q=null;var v=true;var f=r;var m=17;var k=19;var u=1;var a=new GCopyrightCollection();var t=false;var o=null;var s=null;var d=[];var w="image/png";var b="Layer"+new Date().getTime()+"_"+(_G_COUNTER++);this.setFormat=function(y){w=y;if(t){if(g!=null){l();x()}}};this.getFormat=function(){return w};this.addCopyright=function(y){a.addCopyright(y)};this.getCopyrights=function(y,z){return a.getCopyrights(y,z)};this.getProperty=function(y){return d[y]};this.setProperty=function(y,z){if(y!=null&&y!=""){d[y]=z}};this.getVisible=function(){return v};this.setMinZoomLevel=function(y){m=y};this.setMaxZoomLevel=function(y){k=y};this.getMinZoomLevel=function(){return m};this.getMaxZoomLevel=function(){return k};this.setOpacity=function(y){if(y!=null&&y>=0&&y<=1){u=y}if(t){if(g!=null){l();x()}}};this.getOpacity=function(){return u};this.setStyleLayerDescriptorUrl=function(y){o=y};this.getStyleLayerDescriptorUrl=function(){return o};this.setStyleLayerDescriptorText=function(y){s=y};this.getStyleLayerDescriptorText=function(){return s};this.setVisible=function(y){try{v=y;if(v){l();x()}else{q.hide()}}catch(z){}};this.initialize=function(){if(t){return}x();t=true};function x(){var y=new GTileLayer(a,m,k);y.getTileUrl=c;y.isPng=function(){if(w=="image/png"){return true}else{return false}};y.getOpacity=function(){return u};q=new GTileLayerOverlay(y);g.addOverlay(q)}function l(){if(g!=null){g.removeOverlay(q)}}function c(A,y){if(!v||y<m||y>k){return""}var B=e.replace("%2",""+Math.floor(Math.random()*G_NUM_SERVERS));var C=B+"?tileid="+p(A.x,A.y,y);if(f!=null&&f!=""&&f.length>0){C+="&layers="+j(f.join(","))}if(o!=null){C+="&SLD="+j(o)}if(w!=null){C+="&format="+encodeURIComponent(w)}if(s!=null){C+="&SLD_BODY="+j(s)}C+="&IsEncoded=true&SRS=EPSG:4326&REQUEST=MAP";for(var z in d){var D=d[z];if(D!=null&&D!=""){if(typeof(D)!=="undefined"&&typeof(D)!=="function"){C+=("&"+z+"="+encodeURIComponent(D))}}}return C}function p(A,B,E){var y="";for(var D=E;D>0;D--){var C="0";var z=1<<(D-1);if((A&z)!=0){C++}if((B&z)!=0){C++;C++}y+=C}return y}function j(y){return encodeURIComponent(y).replace(/%/g,"._-")}}function GoogleWMSLayer(f,q,d){var j=d;if(!j){j=_G_DMP_SERVER_NAME+"/VEParcelTileServer.aspx"}var g=f;var p=null;var u=true;var e=q;var a=17;var h=19;var s=false;var o=null;var r=null;var t=[];var l="image/png";var m="Layer"+new Date().getTime()+"_"+(_G_COUNTER++);this.setFormat=function(v){l=v};this.getFormat=function(){return l};this.getProperty=function(v){return t[v]};this.setProperty=function(v,w){if(v!=null&&v!=""){t[v]=w}if(s){this.onviewchange()}};this.setStyleLayerDescriptorUrl=function(v){o=v;if(s){this.onviewchange()}};this.getStyleLayerDescriptorUrl=function(){return o};this.setStyleLayerDescriptorText=function(v){r=v;if(s){this.onviewchange()}};this.getStyleLayerDescriptorText=function(){return r};this.getVisible=function(){return u};this.setMinZoomLevel=function(v){a=v;if(s){this.onviewchange()}};this.setMaxZoomLevel=function(v){h=v;if(s){this.onviewchange()}};this.getMinZoomLevel=function(){return a};this.getMaxZoomLevel=function(){return h};this.setVisible=function(v){u=v;try{if(u){this.onviewchange()}else{p.hide()}}catch(w){}};this.onviewchange=function(B){if(p){g.removeOverlay(p)}if(!b.getVisible()){return}var D=g.getZoom();if(a>D||h<D){return}var v=g.getBounds();var A=g.getSize();var E=v.getSouthWest();var C=v.getNorthEast();var F="?bbox="+E.lng()+","+E.lat()+","+C.lng()+","+C.lat();var z="";z+=j+F;var w=encodeURIComponent;if((n>=5.5)&&(n<7)&&(document.body.filters)&&(typeof(d)=="undefined"||d==null)&&l!=null&&l.toLowerCase().indexOf("png")>-1){w=k;z+="&IsEncoded=true"}z+="&width="+A.width;z+="&height="+A.height;if(e!=null&&e!=""&&e.length>0){z+="&layers="+w(e.join(","))}if(o!=null){z+="&SLD="+w(o)}if(l!=null){z+="&format="+w(l)}if(r!=null){z+="&SLD_BODY="+w(r)}z+="&SRS=EPSG:4326&REQUEST=MAP";for(var x in t){var y=t[x];if(y!=null&&y!=""){if(typeof(y)!=="undefined"&&typeof(y)!=="function"){z+=("&"+x+"="+w(y))}}}p=new GGroundOverlay(z,v);g.addOverlay(p)};var c=navigator.appVersion.split("MSIE");var n=parseFloat(c[1]);var b=this;this.initialize=function(){if(s){return}GEvent.bind(g,"moveend",b,b.onviewchange);b.onviewchange();s=true};function k(v){return encodeURIComponent(v).replace(/%/g,"._-")}}function TiledLayer(d,c,a){var b=null;if(typeof(GMap2)!="undefined"&&d instanceof GMap2){b=new GoogleTiledLayer(d,c,a);this.addCopyright=function(e){b.addCopyright(e)};this.getCopyrights=function(e,f){return b.getCopyrights(e,f)}}else{if(typeof(VEMap)!="undefined"&&d instanceof VEMap){b=new VETiledLayer(d,c,a);this.setZIndex=function(e){b.setZIndex(e)};this.getZIndex=function(){return b.getZIndex()}}else{return null}}this.setFormat=function(e){b.setFormat(e)};this.getFormat=function(){return b.getFormat()};this.setProperty=function(e,f){b.setProperty(e,f)};this.getProperty=function(e){return b.getProperty(e)};this.setVisible=function(e){b.setVisible(e)};this.getVisible=function(){return b.getVisible()};this.setMinZoomLevel=function(e){b.setMinZoomLevel(e)};this.getMinZoomLevel=function(){return b.getMinZoomLevel()};this.setMaxZoomLevel=function(e){b.setMaxZoomLevel(e)};this.getMaxZoomLevel=function(){return b.getMaxZoomLevel()};this.setOpacity=function(e){b.setOpacity(e)};this.getOpacity=function(){return b.getOpacity()};this.setStyleLayerDescriptorUrl=function(e){b.setStyleLayerDescriptorUrl(e)};this.getStyleLayerDescriptorUrl=function(){return b.getStyleLayerDescriptorUrl()};this.setStyleLayerDescriptorText=function(e){b.setStyleLayerDescriptorText(e)};this.getStyleLayerDescriptorText=function(){return b.getStyleLayerDescriptorText()};this.initialize=function(){b.initialize()};this.draw=function(){}}function VETiledLayer(u,p,e){gInitializeDMPLayers(u);var g="http://t%2.parcelstream.com/";if(!e){e=g+"VEParcelTileServer.aspx"}var t=true;var f=p;var a=17;var h=19;var b=1;var r=false;var c=100;var n=null;var q=null;var s=[];var k="image/png";var l="Layer"+new Date().getTime()+"_"+(_G_COUNTER++);this.setFormat=function(w){k=w};this.getFormat=function(){return k};this.setZIndex=function(w){c=w};this.getZIndex=function(){return c};this.getProperty=function(w){return s[w]};this.setProperty=function(w,x){if(w!=null&&w!=""){s[w]=x}};this.getVisible=function(){return t};this.setMinZoomLevel=function(w){a=w;if(r){if(u!=null){d();v()}}};this.setMaxZoomLevel=function(w){h=w;if(r){if(u!=null){d();v()}}};this.getMinZoomLevel=function(){return a};this.getMaxZoomLevel=function(){return h};this.setOpacity=function(w){if(w!=null&&w>=0&&w<=1){b=w}if(r){if(u!=null){d();v()}}};this.getOpacity=function(){return b};this.setStyleLayerDescriptorUrl=function(w){n=w;if(r){if(u!=null){d();v()}}};this.getStyleLayerDescriptorUrl=function(){return n};this.setStyleLayerDescriptorText=function(w){q=w;if(r){if(u!=null){d();v()}}};this.getStyleLayerDescriptorText=function(){return q};this.setVisible=function(w){try{t=w;if(this.getVisible()){if(o(u.ShowTileLayer)){u.ShowTileLayer(l)}else{if(o(u.ShowLayer)){d();v()}}}else{if(o(u.HideTileLayer)){u.HideTileLayer(l)}else{if(o(u.HideLayer)){d()}}}}catch(x){}};_this=this;this.initialize=function(){if(r){return}v();r=true};function v(){var y=m();var x=new VETileSourceSpecification(l,y);x.NumServers=G_NUM_SERVERS;x.MinZoomLevel=a;x.MaxZoomLevel=h;x.Opacity=b;x.ZIndex=c;if(o(u.AddTileLayer)){if(u!=null){u.AddTileLayer(x,true)}}else{if(o(u.AddLayer)){u.AddTileSource(x);var w=new VELayerSpecification(VELayerType.VETileSource,l,l);w.ZIndex=c;w.Opacity=b;u.AddLayer(w)}}}function d(){if(u!=null){try{if(o(u.DeleteTileLayer)){u.DeleteTileLayer(l)}else{if(o(u.DeleteLayer)&&o(u.DeleteTileSource)){u.DeleteLayer(l);u.DeleteTileSource(l)}}}catch(w){}}}function o(w){return(typeof(w)!="undefined"&&w!=null)}function m(){var y=e+"?tileid=%4";if(f!=null&&f!=""&&f.length>0){y+="&layers="+j(f.join(","))}if(n!=null){y+="&SLD="+j(n)}if(k!=null){y+="&format="+encodeURIComponent(k)}if(q!=null){y+="&SLD_BODY="+j(q)}y+="&IsEncoded=true&SRS=EPSG:4326&REQUEST=MAP";for(var x in s){var w=s[x];if(w!=null&&w!=""){if(typeof(w)!=="undefined"&&typeof(w)!=="function"){y+=("&"+x+"="+encodeURIComponent(w))}}}y+="&OverrideMapStyle="+j("<OverrideMapStyle><FORCE>1</FORCE></OverrideMapStyle>");return y}function j(w){return encodeURIComponent(w).replace(/%/g,"._-")}}function VEWMSLayer(w,r,f){gInitializeDMPLayers(w);var k=f;if(!k){k=_G_DMP_SERVER_NAME+"/VEParcelTileServer.aspx"}var l=null;var v=true;var g=r;var a=17;var j=19;var b=1;var t=false;var p=null;var s=null;var u=[];var c=2;var m="image/png";var n="Layer"+new Date().getTime()+"_"+(_G_COUNTER++);this.setFormat=function(x){m=x};this.getFormat=function(){return m};this.setZIndex=function(x){c=x};this.getZIndex=function(){return c};this.getProperty=function(x){return u[x]};this.setProperty=function(x,y){if(x!=null&&x!=""){u[x]=y}};this.setStyleLayerDescriptorUrl=function(x){p=x};this.getStyleLayerDescriptorUrl=function(){return p};this.setStyleLayerDescriptorText=function(x){s=x};this.getStyleLayerDescriptorText=function(){return s};this.getVisible=function(){return v};this.setMinZoomLevel=function(x){a=x};this.setMaxZoomLevel=function(x){j=x};this.getMinZoomLevel=function(){return a};this.getMaxZoomLevel=function(){return j};this.setOpacity=function(x){if(x!=null&&x>=0&&x<=1){b=x}};this.getOpacity=function(){return b};this.setVisible=function(z){try{v=z;if(this.getVisible()){this.onviewchange(null)}else{var A=q();var x=A.firstChild;if(l!=null){x.removeChild(l);l=null}}}catch(y){}};this.onviewchange=function(L){if(!_this.getVisible()){return}var B=q();var I=B.firstChild;if(l!=null){I.removeChild(l);l=null}var C=w.GetZoomLevel();if(a>C||j<C){return}var K=w.GetWidth();var A=w.GetHeight();var P=0;var z=0;var R=P+w.GetWidth();var y=z+w.GetHeight();var G=w.PixelToLatLong(new VEPixel(P,y));var Q=w.PixelToLatLong(new VEPixel(R,z));var D=G.Longitude;var H=G.Latitude;var F=Q.Longitude;var J=Q.Latitude;var M="";M+=k;M+="?bbox="+D+","+H+","+F+","+J;var E=encodeURIComponent;if((o>=5.5)&&(o<7)&&(document.body.filters)&&(typeof(f)=="undefined"||f==null)&&m!=null&&m.toLowerCase().indexOf("png")>-1){E=h;M+="&IsEncoded=true"}M+="&width="+K;M+="&height="+A;if(g!=null&&g!=""&&g.length>0){M+="&layers="+E(g.join(","))}if(p!=null){M+="&SLD="+E(p)}if(m!=null){M+="&format="+E(m)}if(s!=null){M+="&SLD_BODY="+E(s)}M+="&SRS=EPSG:4326&REQUEST=MAP";for(var N in u){var x=u[N];if(x!=null&&x!=""){if(typeof(x)!=="undefined"&&typeof(x)!=="function"){M+=("&"+N+"="+E(x))}}}l=document.createElement("IMG");l.setAttribute("id","MDE"+n);l.id="MDE"+n;I.appendChild(l);var O=0-parseInt(I.style.top);var S=0-parseInt(I.style.left);l.style.left=S+"px";l.style.top=O+"px";l.style.position="absolute";l.style.width=K+"px";l.style.height=A+"px";l.style.opacity=b;l.style.filter="alpha(opacity="+(b*100)+")";l.style.zIndex=c;l.setAttribute("src",M);if(m!=null&&m.toLowerCase().indexOf("png")>-1){l=d(l)}};var e=navigator.appVersion.split("MSIE");var o=parseFloat(e[1]);function d(D){if((o>=5.5)&&(o<7)&&(document.body.filters)){var x=D.id;var z=(D.id)?"id='"+D.id+"' ":"";var B=(D.className)?"class='"+D.className+"' ":"";var y=(D.title)?"title='"+D.title+"' ":"title='"+D.alt+"' ";var A="display:inline-block;"+D.style.cssText;var C="<span "+z+B+y+' style="width:'+D.width+"px; height:"+D.height+"px;"+A+";filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+D.src+"', sizingMethod='scale');\"></span>";D.outerHTML=C;return document.getElementById(x)}return D}function q(){return document.getElementById(w.ID)}_this=this;this.initialize=function(){if(t){return}w.AttachEvent("onchangeview",this.onviewchange);this.onviewchange();t=true};function h(x){return encodeURIComponent(x).replace(/%/g,"._-")}}function WMSLayer(d,c,a){var b=null;if(typeof(GMap2)!="undefined"&&d instanceof GMap2){b=new GoogleWMSLayer(d,c,a)}else{if(typeof(VEMap)!="undefined"&&d instanceof VEMap){b=new VEWMSLayer(d,c,a);this.setZIndex=function(e){b.setZIndex(e)};this.getZIndex=function(){return b.getZIndex()};this.setOpacity=function(e){b.setOpacity(e)};this.getOpacity=function(){return b.getOpacity()}}else{return null}}this.setFormat=function(e){b.setFormat(e)};this.getFormat=function(){return b.getFormat()};this.setProperty=function(e,f){b.setProperty(e,f)};this.getProperty=function(e){return b.getProperty(e)};this.setVisible=function(e){b.setVisible(e)};this.getVisible=function(){return b.getVisible()};this.setMinZoomLevel=function(e){b.setMinZoomLevel(e)};this.getMinZoomLevel=function(){return b.getMinZoomLevel()};this.setMaxZoomLevel=function(e){b.setMaxZoomLevel(e)};this.getMaxZoomLevel=function(){return b.getMaxZoomLevel()};this.setStyleLayerDescriptorUrl=function(e){b.setStyleLayerDescriptorUrl(e)};this.getStyleLayerDescriptorUrl=function(){return b.getStyleLayerDescriptorUrl()};this.setStyleLayerDescriptorText=function(e){b.setStyleLayerDescriptorText(e)};this.getStyleLayerDescriptorText=function(){return b.getStyleLayerDescriptorText()};this.initialize=function(){b.initialize()};this.draw=function(){};this.onviewchange=b.onviewchange};(function(a){var c=(a.browser.msie?"paste":"input")+".mask";var b=(window.orientation!=undefined);a.mask={definitions:{"9":"[0-9]",a:"[A-Za-z]","*":"[A-Za-z0-9]"}};a.fn.extend({caret:function(e,f){if(this.length==0){return}if(typeof e=="number"){f=(typeof f=="number")?f:e;return this.each(function(){if(this.setSelectionRange){this.focus();this.setSelectionRange(e,f)}else{if(this.createTextRange){var g=this.createTextRange();g.collapse(true);g.moveEnd("character",f);g.moveStart("character",e);g.select()}}})}else{if(this[0].setSelectionRange){e=this[0].selectionStart;f=this[0].selectionEnd}else{if(document.selection&&document.selection.createRange){var d=document.selection.createRange();e=0-d.duplicate().moveStart("character",-100000);f=e+d.text.length}}return{begin:e,end:f}}},unmask:function(){return this.trigger("unmask")},mask:function(j,d){if(!j&&this.length>0){var f=a(this[0]);var g=f.data("tests");return a.map(f.data("buffer"),function(l,m){return g[m]?l:null}).join("")}d=a.extend({placeholder:"_",completed:null},d);var k=a.mask.definitions;var g=[];var e=j.length;var i=null;var h=j.length;a.each(j.split(""),function(m,l){if(l=="?"){h--;e=m}else{if(k[l]){g.push(new RegExp(k[l]));if(i==null){i=g.length-1}}else{g.push(null)}}});return this.each(function(){var r=a(this);var m=a.map(j.split(""),function(x,y){if(x!="?"){return k[x]?d.placeholder:x}});var n=false;var q=r.val();r.data("buffer",m).data("tests",g);function v(x){while(++x<=h&&!g[x]){}return x}function t(x){while(!g[x]&&--x>=0){}for(var y=x;y<h;y++){if(g[y]){m[y]=d.placeholder;var z=v(y);if(z<h&&g[y].test(m[z])){m[y]=m[z]}else{break}}}s();r.caret(Math.max(i,x))}function u(y){for(var A=y,z=d.placeholder;A<h;A++){if(g[A]){var B=v(A);var x=m[A];m[A]=z;if(B<h&&g[B].test(x)){z=x}else{break}}}}function l(y){var x=a(this).caret();var z=y.keyCode;n=(z<16||(z>16&&z<32)||(z>32&&z<41));if((x.begin-x.end)!=0&&(!n||z==8||z==46)){w(x.begin,x.end)}if(z==8||z==46||(b&&z==127)){t(x.begin+(z==46?0:-1));return false}else{if(z==27){r.val(q);r.caret(0,p());return false}}}function o(B){if(n){n=false;return(B.keyCode==8)?false:null}B=B||window.event;var C=B.charCode||B.keyCode||B.which;var z=a(this).caret();if(B.ctrlKey||B.altKey||B.metaKey){return true}else{if((C>=32&&C<=125)||C>186){var x=v(z.begin-1);if(x<h){var A=String.fromCharCode(C);if(g[x].test(A)){u(x);m[x]=A;s();var y=v(x);a(this).caret(y);if(d.completed&&y==h){d.completed.call(r)}}}}}return false}function w(x,y){for(var z=x;z<y&&z<h;z++){if(g[z]){m[z]=d.placeholder}}}function s(){return r.val(m.join("")).val()}function p(y){var z=r.val();var C=-1;for(var B=0,x=0;B<h;B++){if(g[B]){m[B]=d.placeholder;while(x++<z.length){var A=z.charAt(x-1);if(g[B].test(A)){m[B]=A;C=B;break}}if(x>z.length){break}}else{if(m[B]==z[x]&&B!=e){x++;C=B}}}if(!y&&C+1<e){r.val("");w(0,h)}else{if(y||C+1>=e){s();if(!y){r.val(r.val().substring(0,C+1))}}}return(e?B:i)}if(!r.attr("readonly")){r.one("unmask",function(){r.unbind(".mask").removeData("buffer").removeData("tests")}).bind("focus.mask",function(){q=r.val();var x=p();s();setTimeout(function(){if(x==j.length){r.caret(0,x)}else{r.caret(x)}},0)}).bind("blur.mask",function(){p();if(r.val()!=q){r.change()}}).bind("keydown.mask",l).bind("keypress.mask",o).bind(c,function(){setTimeout(function(){r.caret(p(true))},0)})}p()})}})})(jQuery);